Skip to content

Commit

Permalink
Pet specific foods and special treats handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Quackster committed May 8, 2024
1 parent 974dce5 commit eafa885
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.alexdev.kepler.game.entity.Entity;
import org.alexdev.kepler.game.entity.EntityType;
import org.alexdev.kepler.game.item.Item;
import org.alexdev.kepler.game.item.base.ItemBehaviour;
import org.alexdev.kepler.game.pathfinder.Position;
import org.alexdev.kepler.game.pets.Pet;
import org.alexdev.kepler.game.player.Player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ private boolean tryEat() {
.filter(item -> (item.hasBehaviour(ItemBehaviour.PET_FOOD) ||
(
(petType == PetType.CAT && item.hasBehaviour(ItemBehaviour.PET_CAT_FOOD)) ||
(petType == PetType.DOG && item.hasBehaviour(ItemBehaviour.PET_DOG_FOOD))
(petType == PetType.DOG && item.hasBehaviour(ItemBehaviour.PET_DOG_FOOD)) ||
(petType == PetType.CROC && item.hasBehaviour(ItemBehaviour.PET_CROC_FOOD))
)) &&
!item.getCustomData().equalsIgnoreCase("4") &&
item.getTile().getOtherEntities(this.pet).isEmpty()).toList();
Expand Down Expand Up @@ -222,14 +223,21 @@ public void eatingComplete(boolean reapBenefits) {

if (currentItem != null &&
currentItem.hasBehaviour(ItemBehaviour.PET_FOOD)) {

if (StringUtils.isNumeric(currentItem.getCustomData())) {
int state = Integer.parseInt(currentItem.getCustomData()) + 1;

if (state <= 4) {
currentItem.setCustomData(String.valueOf(state));
currentItem.updateStatus();
currentItem.save();
if (currentItem.hasBehaviour(ItemBehaviour.PET_CAT_FOOD) ||
currentItem.hasBehaviour(ItemBehaviour.PET_DOG_FOOD)) {

this.room.getMapping().removeItem(currentItem);
currentItem.delete();
} else {
if (StringUtils.isNumeric(currentItem.getCustomData())) {
int state = Integer.parseInt(currentItem.getCustomData()) + 1;

if (state <= 4) {
currentItem.setCustomData(String.valueOf(state));
currentItem.updateStatus();
currentItem.save();
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tools/migrations/update.1.5.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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');
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_food', `interactor`='pet_food' WHERE `sprite` IN ('petfood1','petfood2','petfood3');
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_cat_food', `interactor`='pet_food' WHERE `sprite` IN ('goodie2');
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_dog_food', `interactor`='pet_food' WHERE `sprite` IN ('goodie1');
UPDATE `items_definitions` SET `behaviour`='can_stand_on_top,requires_rights_for_interaction,pet_croc_food', `interactor`='pet_food' WHERE `sprite` IN ('petfood4');

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');
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 comments on commit eafa885

Please sign in to comment.