mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-16 21:02:44 +08:00
cf67c44f22
* feat:cooking food ingredient(aka:compound) implementation Implement food ingredient(compound) feature.Need a thorough test and still has some work to do. * small bug fix;implement fish processing * Update src/main/java/emu/grasscutter/server/packet/send/PacketItemAddHintNotify.java Co-authored-by: Luke H-W <Birdulon@users.noreply.github.com> * Update Inventory.java * Update Inventory.java Co-authored-by: Luke H-W <Birdulon@users.noreply.github.com>
60 lines
1.6 KiB
Java
60 lines
1.6 KiB
Java
package emu.grasscutter.game.managers.cooking;
|
|
|
|
import dev.morphia.annotations.Entity;
|
|
import lombok.Getter;
|
|
|
|
|
|
@Entity
|
|
public class ActiveCookCompoundData {
|
|
private final int costTime;
|
|
@Getter
|
|
private final int compoundId;
|
|
@Getter
|
|
private int totalCount;
|
|
private int startTime;
|
|
|
|
public ActiveCookCompoundData(int compoundId, int processTime, int count, int startTime) {
|
|
this.compoundId = compoundId;
|
|
this.costTime = processTime;
|
|
this.totalCount = count;
|
|
this.startTime = startTime;
|
|
}
|
|
|
|
public int getOutputCount(int currentTime) {
|
|
int cnt = (currentTime - startTime) / costTime;
|
|
if (cnt > totalCount) return totalCount;
|
|
else return cnt;
|
|
}
|
|
|
|
public int getWaitCount(int currentTime) {
|
|
return totalCount - getOutputCount(currentTime);
|
|
}
|
|
|
|
/**
|
|
* Get the timestamp of next output.
|
|
* If all finished,return 0
|
|
*/
|
|
public int getOutputTime(int currentTime) {
|
|
int cnt = getOutputCount(currentTime);
|
|
if (cnt == totalCount) return 0;
|
|
else return startTime + (cnt + 1) * costTime;
|
|
}
|
|
|
|
public void addCompound(int count, int currentTime) {
|
|
if (getOutputCount(currentTime) == totalCount) startTime = currentTime - totalCount * costTime;
|
|
totalCount += count;
|
|
}
|
|
|
|
/**
|
|
* Take away all finished compound.
|
|
*
|
|
* @return The number of finished items.
|
|
*/
|
|
public int takeCompound(int currentTime) {
|
|
int count = getOutputCount(currentTime);
|
|
startTime += costTime * count;
|
|
totalCount -= count;
|
|
return count;
|
|
}
|
|
}
|