feat:cooking food ingredient(aka:compound) implementation (#1858)

* 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>
This commit is contained in:
dragon
2022-10-17 16:48:05 +08:00
committed by GitHub
Unverified
parent 1ecc3f4390
commit cf67c44f22
27 changed files with 7265 additions and 77 deletions
@@ -0,0 +1,59 @@
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;
}
}