Skip to content

Commit

Permalink
Use the control ID to check whether the creatures can be picked up
Browse files Browse the repository at this point in the history
  • Loading branch information
tonihele committed Oct 27, 2024
1 parent 80b0353 commit 1c8eadd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
16 changes: 3 additions & 13 deletions src/toniarts/openkeeper/game/controller/GameWorldController.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ private void notifyOnSold(short playerId, List<Point> soldTiles) {
@Override
public void pickUp(EntityId entity, short playerId) {
PlayerHandControl playerHandControl = playerControllers.get(playerId).getHandControl();
if (!playerHandControl.isFull() && canPickUpEntity(entity, playerId, entityData, mapController)) {
if (!playerHandControl.isFull() && canPickUpEntity(entity, playerId, entityData)) {
putToKeeperHand(playerHandControl, entity, playerId);
}
}
Expand Down Expand Up @@ -636,7 +636,7 @@ private void putToKeeperHand(PlayerHandControl playerHandControl, EntityId entit
}
}

private static boolean canPickUpEntity(EntityId entityId, short playerId, EntityData entityData, IMapController mapController) {
private static boolean canPickUpEntity(EntityId entityId, short playerId, EntityData entityData) {
// TODO: Somewhere common shared static, can share the rules with the UI client

// Check if picked up already
Expand All @@ -645,18 +645,8 @@ private static boolean canPickUpEntity(EntityId entityId, short playerId, Entity
return false;
}

// The if entity if help up us (prison or torture), we have the authority and ownership
Owner owner = entityData.getComponent(entityId, Owner.class);
CreatureImprisoned imprisoned = entityData.getComponent(entityId, CreatureImprisoned.class);
CreatureTortured tortured = entityData.getComponent(entityId, CreatureTortured.class);
Position position = entityData.getComponent(entityId, Position.class);
Point p = WorldUtils.vectorToPoint(position.position);
if ((imprisoned != null || tortured != null) && mapController.getMapData().getTile(p).getOwnerId() == playerId) {
return true;
}

// The owner only
if (owner == null || owner.ownerId != playerId) {
if (owner == null || owner.controlId != playerId) {
return false;
}

Expand Down
7 changes: 6 additions & 1 deletion src/toniarts/openkeeper/view/control/EntityViewControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public boolean isInteractable(short playerId) {
if (interaction == null) {
return false;
}
return (interaction.interactable || interaction.slappable) && getOwnerId() == playerId;
return (interaction.interactable || interaction.slappable) && getControlId() == playerId;
}

@Override
Expand Down Expand Up @@ -197,6 +197,11 @@ public short getOwnerId() {
return entity.get(Owner.class).ownerId;
}

@Override
public short getControlId() {
return entity.get(Owner.class).controlId;
}

@Override
public void pickUp(short playerId) {

Expand Down
7 changes: 7 additions & 0 deletions src/toniarts/openkeeper/view/control/IEntityViewControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ public enum DroppableStatus {
*/
public short getOwnerId();

/**
* Get the control ID of the entity
*
* @return the player ID of the one in charge
*/
public short getControlId();

/**
* Get the entity ID
*
Expand Down

0 comments on commit 1c8eadd

Please sign in to comment.