mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-14 07:55:57 +01:00
feat: implement home animals (#2329)
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package emu.grasscutter.game.entity;
|
||||
|
||||
import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.excels.HomeWorldAnimalData;
|
||||
import emu.grasscutter.game.props.ElementType;
|
||||
import emu.grasscutter.game.world.Position;
|
||||
import emu.grasscutter.game.world.Scene;
|
||||
import emu.grasscutter.net.proto.VisionTypeOuterClass;
|
||||
import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketSceneEntityDisappearNotify;
|
||||
import lombok.Getter;
|
||||
|
||||
public class EntityHomeAnimal extends EntityMonster implements Rebornable {
|
||||
private int rebornCDTickCount;
|
||||
private final Position rebornPos;
|
||||
@Getter
|
||||
private final int rebirth;
|
||||
@Getter
|
||||
private final int rebirthCD;
|
||||
private boolean disappeared;
|
||||
|
||||
public EntityHomeAnimal(Scene scene, HomeWorldAnimalData data, Position pos) {
|
||||
super(scene, GameData.getMonsterDataMap().get(data.getMonsterID()), pos, 1);
|
||||
|
||||
this.rebornPos = pos.clone();
|
||||
this.rebirth = data.getIsRebirth();
|
||||
this.rebirthCD = data.getRebirthCD();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void damage(float amount, int killerId, ElementType attackType) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(int sceneTime) {
|
||||
super.onTick(sceneTime);
|
||||
|
||||
if (this.isInCD()) {
|
||||
this.rebornCDTickCount--;
|
||||
if (this.rebornCDTickCount <= 0) {
|
||||
this.reborn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getRebornPos() {
|
||||
return this.rebornPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRebornCD() {
|
||||
return this.rebirthCD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAiKillSelf() {
|
||||
this.getScene().broadcastPacket(new PacketSceneEntityDisappearNotify(this, VisionTypeOuterClass.VisionType.VISION_TYPE_REMOVE));
|
||||
this.rebornCDTickCount = this.getRebornCD();
|
||||
this.disappeared = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reborn() {
|
||||
if (this.disappeared) {
|
||||
this.disappeared = false;
|
||||
this.getPosition().set(this.getRebornPos());
|
||||
this.getScene().broadcastPacket(new PacketSceneEntityAppearNotify(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInCD() {
|
||||
return this.disappeared;
|
||||
}
|
||||
}
|
||||
15
src/main/java/emu/grasscutter/game/entity/Rebornable.java
Normal file
15
src/main/java/emu/grasscutter/game/entity/Rebornable.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package emu.grasscutter.game.entity;
|
||||
|
||||
import emu.grasscutter.game.world.Position;
|
||||
|
||||
public interface Rebornable {
|
||||
Position getRebornPos();
|
||||
|
||||
int getRebornCD();
|
||||
|
||||
void onAiKillSelf();
|
||||
|
||||
void reborn();
|
||||
|
||||
boolean isInCD();
|
||||
}
|
||||
Reference in New Issue
Block a user