Skip to content

Commit eafa885

Browse files
committed
Pet specific foods and special treats handling
1 parent 974dce5 commit eafa885

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

Kepler-Server/src/main/java/org/alexdev/kepler/game/item/interactors/types/PetFoodInteractor.java

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.alexdev.kepler.game.entity.Entity;
44
import org.alexdev.kepler.game.entity.EntityType;
55
import org.alexdev.kepler.game.item.Item;
6+
import org.alexdev.kepler.game.item.base.ItemBehaviour;
67
import org.alexdev.kepler.game.pathfinder.Position;
78
import org.alexdev.kepler.game.pets.Pet;
89
import org.alexdev.kepler.game.player.Player;

Kepler-Server/src/main/java/org/alexdev/kepler/game/room/tasks/PetTask.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ private boolean tryEat() {
182182
.filter(item -> (item.hasBehaviour(ItemBehaviour.PET_FOOD) ||
183183
(
184184
(petType == PetType.CAT && item.hasBehaviour(ItemBehaviour.PET_CAT_FOOD)) ||
185-
(petType == PetType.DOG && item.hasBehaviour(ItemBehaviour.PET_DOG_FOOD))
185+
(petType == PetType.DOG && item.hasBehaviour(ItemBehaviour.PET_DOG_FOOD)) ||
186+
(petType == PetType.CROC && item.hasBehaviour(ItemBehaviour.PET_CROC_FOOD))
186187
)) &&
187188
!item.getCustomData().equalsIgnoreCase("4") &&
188189
item.getTile().getOtherEntities(this.pet).isEmpty()).toList();
@@ -222,14 +223,21 @@ public void eatingComplete(boolean reapBenefits) {
222223

223224
if (currentItem != null &&
224225
currentItem.hasBehaviour(ItemBehaviour.PET_FOOD)) {
225-
226-
if (StringUtils.isNumeric(currentItem.getCustomData())) {
227-
int state = Integer.parseInt(currentItem.getCustomData()) + 1;
228226

229-
if (state <= 4) {
230-
currentItem.setCustomData(String.valueOf(state));
231-
currentItem.updateStatus();
232-
currentItem.save();
227+
if (currentItem.hasBehaviour(ItemBehaviour.PET_CAT_FOOD) ||
228+
currentItem.hasBehaviour(ItemBehaviour.PET_DOG_FOOD)) {
229+
230+
this.room.getMapping().removeItem(currentItem);
231+
currentItem.delete();
232+
} else {
233+
if (StringUtils.isNumeric(currentItem.getCustomData())) {
234+
int state = Integer.parseInt(currentItem.getCustomData()) + 1;
235+
236+
if (state <= 4) {
237+
currentItem.setCustomData(String.valueOf(state));
238+
currentItem.updateStatus();
239+
currentItem.save();
240+
}
233241
}
234242
}
235243
}

tools/migrations/update.1.5.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_food', `interactor`='pet_food' WHERE `sprite` IN ('petfood1','petfood2','petfood3','petfood4');
1+
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_food', `interactor`='pet_food' WHERE `sprite` IN ('petfood1','petfood2','petfood3');
22
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_cat_food', `interactor`='pet_food' WHERE `sprite` IN ('goodie2');
33
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_dog_food', `interactor`='pet_food' WHERE `sprite` IN ('goodie1');
4+
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_croc_food', `interactor`='pet_food' WHERE `sprite` IN ('petfood4');
45

56
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_water_bowl', `interactor`='pet_water_bowl' WHERE `sprite` IN ('waterbowl*1','waterbowl*2','waterbowl*3','waterbowl*4', 'waterbowl*5');
67
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_toy', `interactor`='pet_toy' WHERE `sprite` IN ('toy1', 'toy1*1', 'toy1*2', 'toy1*3', 'toy1*4');

0 commit comments

Comments
 (0)