org.worldgrower.OperationInfo - java examples

Here are the examples of the java api org.worldgrower.OperationInfo taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

59 Examples 7

19 View Complete Implementation : Game.java
Copyright GNU General Public License v3.0
Author : WorldGrower
public static void executeMultipleActionsAndMoveIntelligentWorldObjects(WorldObject playerCharacter, List<OperationInfo> tasks, World world, DungeonMaster dungeonMaster, WorldObject target, WorldPanel worldPanel, ImageInfoReader imageInfoReader, SoundIdReader soundIdReader) {
    if (tasks.size() > 0) {
        OperationInfo task = tasks.get(0);
        ManagedOperation action = task.getManagedOperation();
        int[] args = task.getArgs();
        if (canActionExecute(playerCharacter, action, args, world, target)) {
            ActionListener guiMoveAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent arg0) {
                    executeAction(playerCharacter, action, args, world, dungeonMaster, target, worldPanel, imageInfoReader, soundIdReader);
                }
            };
            ActionListener guiAfterMoveAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent arg0) {
                    List<OperationInfo> subTasks = tasks.subList(1, tasks.size());
                    executeMultipleActionsAndMoveIntelligentWorldObjects(playerCharacter, subTasks, world, dungeonMaster, playerCharacter, worldPanel, imageInfoReader, soundIdReader);
                }
            };
            worldPanel.movePlayerCharacter(args, guiMoveAction, guiAfterMoveAction);
        } else {
        // only used for goto path finding. If action cannot be executed, just silently ignore
        // throw actionCannotBeExecuted(action, args);
        }
    }
}

19 View Complete Implementation : HistoryImpl.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public HistoryItem actionPerformed(OperationInfo operationInfo, Turn turn) {
    HistoryItem historyItem = null;
    ManagedOperation action = operationInfo.getManagedOperation();
    boolean shouldLogAction = shouldLogAction(action);
    if (shouldLogAction) {
        historyItem = new HistoryItem(getNextHistoryId(), operationInfo, turn, currentAdditionalValue, historyWorldObjects);
        currentAdditionalValue = null;
        addHistoryItem(historyItem);
        updateHistoryWorldObjects(operationInfo);
    }
    addAsLastPerformedOperation(operationInfo);
    return historyItem;
}

19 View Complete Implementation : HistoryImpl.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private void updateHistoryWorldObjects(OperationInfo operationInfo) {
    historyWorldObjects.add(operationInfo.getPerformer());
    historyWorldObjects.add(operationInfo.getTarget());
}

19 View Complete Implementation : ApothecaryGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    List<WorldObject> unownedApothecaries = BuildingGenerator.findUnownedBuildingsForClaiming(performer, Constants.APOTHECARY_QUALITY, w -> BuildingGenerator.isApothecary(w), world);
    if (unownedApothecaries.size() > 0) {
        return new OperationInfo(performer, unownedApothecaries.get(0), Args.EMPTY, Actions.CLAIM_BUILDING_ACTION);
    } else {
        OperationInfo buyBuildingOperationInfo = HousePropertyUtils.createBuyBuildingOperationInfo(performer, BuildingType.APOTHECARY, world);
        if (buyBuildingOperationInfo != null) {
            return buyBuildingOperationInfo;
        } else {
            return Goals.CREATE_APOTHECARY_GOAL.calculateGoal(performer, world);
        }
    }
}

19 View Complete Implementation : UTestSetTaxesGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Test
public void testCalculateAndPerformGoalSetTaxRate() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer = createPerformer();
    WorldObject villagersOrganization = createVillagersOrganization(world);
    villagersOrganization.setProperty(Constants.SHACK_TAX_RATE, 5);
    villagersOrganization.setProperty(Constants.HOUSE_TAX_RATE, 6);
    villagersOrganization.setProperty(Constants.SHERIFF_WAGE, 7);
    villagersOrganization.setProperty(Constants.TAX_COLLECTOR_WAGE, 8);
    OperationInfo operationInfo = goal.calculateGoal(performer, world);
    operationInfo.perform(world);
    replacedertEquals(0, villagersOrganization.getProperty(Constants.SHACK_TAX_RATE).intValue());
    replacedertEquals(0, villagersOrganization.getProperty(Constants.HOUSE_TAX_RATE).intValue());
    replacedertEquals(10, villagersOrganization.getProperty(Constants.SHERIFF_WAGE).intValue());
    replacedertEquals(10, villagersOrganization.getProperty(Constants.TAX_COLLECTOR_WAGE).intValue());
}

19 View Complete Implementation : TradeGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    OperationInfo sellOperationInfo = BuySellUtils.getSellOperationInfo(performer, world, DISTANCE);
    if (sellOperationInfo != null) {
        return sellOperationInfo;
    }
    OperationInfo buyOperationInfo = BuySellUtils.getBuyOperationInfo(performer, buyingProperties, world);
    if (buyOperationInfo != null) {
        return buyOperationInfo;
    }
    return null;
}

19 View Complete Implementation : CreateWineGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    Integer breweryId = BuildingGenerator.getBreweryId(performer);
    if (performer.getProperty(Constants.INVENTORY).getQuanreplacedyFor(Constants.GRAPE) < 5) {
        OperationInfo harvestGrapesOperationInfo = Goals.HARVEST_GRAPES_GOAL.calculateGoal(performer, world);
        if (harvestGrapesOperationInfo != null) {
            return harvestGrapesOperationInfo;
        } else {
            WorldObject target = BuildLocationUtils.findOpenLocationNearExistingProperty(performer, BuildingDimensions.GRAPE_VINE, world, TerrainResource.GRAPES);
            if (target != null) {
                return new OperationInfo(performer, target, Args.EMPTY, Actions.PLANT_GRAPE_VINE_ACTION);
            } else {
                return null;
            }
        }
    } else if (breweryId == null) {
        return Goals.BREWERY_GOAL.calculateGoal(performer, world);
    } else {
        WorldObject brewery = world.findWorldObjectById(breweryId);
        return new OperationInfo(performer, brewery, Args.EMPTY, Actions.BREW_WINE_ACTION);
    }
}

19 View Complete Implementation : BreweryGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    List<WorldObject> unownedBreweries = BuildingGenerator.findUnownedBuildingsForClaiming(performer, Constants.BREWERY_QUALITY, w -> BuildingGenerator.isBrewery(w), world);
    if (unownedBreweries.size() > 0) {
        return new OperationInfo(performer, unownedBreweries.get(0), Args.EMPTY, Actions.CLAIM_BUILDING_ACTION);
    } else {
        OperationInfo buyBuildingOperationInfo = HousePropertyUtils.createBuyBuildingOperationInfo(performer, BuildingType.BREWERY, world);
        if (buyBuildingOperationInfo != null) {
            return buyBuildingOperationInfo;
        } else {
            return Goals.CREATE_BREWERY_GOAL.calculateGoal(performer, world);
        }
    }
}

19 View Complete Implementation : UTestBuySellUtils.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Test
public void testExecuteBuyClothesOperationInfo() {
    World world = new WorldImpl(1, 1, null, null);
    WorldObject performer = TestUtils.createIntelligentWorldObject(3, Constants.INVENTORY, new WorldObjectContainer());
    performer.setProperty(Constants.GOLD, 1000);
    WorldObject target = TestUtils.createIntelligentWorldObject(4, Constants.INVENTORY, new WorldObjectContainer());
    WorldObject inventoryItem = Item.COTTON_SHIRT.generate(1f);
    inventoryItem.setProperty(Constants.SELLABLE, Boolean.TRUE);
    target.getProperty(Constants.INVENTORY).addQuanreplacedy(inventoryItem);
    target.getProperty(Constants.PRICES).setPrice(Item.COTTON_SHIRT, 5);
    target.setProperty(Constants.ITEMS_SOLD, new ItemCountMap());
    target.setProperty(Constants.GOLD, 1000);
    world.addWorldObject(target);
    OperationInfo buyOperationInfo = BuySellUtils.create(performer, target, Item.COTTON_SHIRT, 1, world);
    buyOperationInfo.getManagedOperation().execute(performer, target, buyOperationInfo.getArgs(), world);
    replacedertEquals(0, performer.getProperty(Constants.INVENTORY).getIndexFor(Constants.ITEM_ID, Item.COTTON_SHIRT));
    replacedertEquals(995, performer.getProperty(Constants.GOLD).intValue());
    replacedertEquals(1005, target.getProperty(Constants.GOLD).intValue());
}

19 View Complete Implementation : HouseGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    if (!GroupPropertyUtils.hasMoneyToPayHouseTaxes(performer, world)) {
        return null;
    } else {
        List<WorldObject> unownedHouses = BuildingGenerator.findUnownedBuildingsForClaiming(performer, Constants.SLEEP_COMFORT, w -> BuildingGenerator.isHouse(w), world);
        if (unownedHouses.size() > 0) {
            return new OperationInfo(performer, unownedHouses.get(0), Args.EMPTY, Actions.CLAIM_BUILDING_ACTION);
        } else {
            OperationInfo buyBuildingOperationInfo = HousePropertyUtils.createBuyBuildingOperationInfo(performer, BuildingType.HOUSE, world);
            if (buyBuildingOperationInfo != null) {
                return buyBuildingOperationInfo;
            } else {
                return Goals.CREATE_HOUSE_GOAL.calculateGoal(performer, world);
            }
        }
    }
}

19 View Complete Implementation : StoneGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    OperationInfo buyOperationInfo = BuySellUtils.getBuyOperationInfo(performer, Constants.STONE, QUANreplacedY_TO_BUY, world);
    if (buyOperationInfo != null) {
        return buyOperationInfo;
    } else {
        return Goals.MINE_STONE_GOAL.calculateGoal(performer, world);
    }
}

19 View Complete Implementation : MarkNonEquipedItemsAsSellableGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public final OperationInfo calculateGoal(WorldObject performer, World world) {
    for (IntProperty propertyToSell : sellingProperties) {
        OperationInfo sellOperationInfo = SellablePropertyUtils.calculateGoal(performer, propertyToSell, world);
        if (sellOperationInfo != null) {
            return sellOperationInfo;
        }
    }
    return null;
}

19 View Complete Implementation : BackgroundImpl.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private void checkForNewRevengeTargets(WorldObject backgroundPerformer, World world) {
    Collection<OperationInfo> importantOperationInfos = world.getHistory().getAllLastPerformedOperations();
    for (OperationInfo operationInfo : importantOperationInfos) {
        // performer should exist, this method can be called in the onTurn method
        // during the onTurn method the performer may have been deleted
        if (operationInfo.getTarget().equals(backgroundPerformer) && world.exists(backgroundPerformer) && world.exists(operationInfo.getPerformer())) {
            handlePerformerWasAttacked(backgroundPerformer, operationInfo);
        }
    }
    cleanupRevengeTargets(world);
}

19 View Complete Implementation : AnimationPainter.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private void initializeMagicCastersAndTargets(World world, ImageInfoReader imageInfoReader) {
    magicCasters.clear();
    magicTargets.clear();
    for (WorldObject intelligentWorldObject : worldObjects) {
        OperationInfo lastPerformedOperationInfo = world.getHistory().getLastPerformedOperation(intelligentWorldObject);
        if (lastPerformedOperationInfo != null) {
            if (lastPerformedOperationInfo.getManagedOperation() instanceof MagicSpell) {
                magicCasters.add(intelligentWorldObject);
            }
            if (lastPerformedOperationInfo.getManagedOperation() instanceof AnimatedAction) {
                AnimatedAction animatedAction = (AnimatedAction) lastPerformedOperationInfo.getManagedOperation();
                List<WorldObject> affectedTargets = animatedAction.getAffectedTargets(lastPerformedOperationInfo.getTarget(), world);
                for (WorldObject affectedTarget : affectedTargets) {
                    magicTargets.add(new MagicTarget(affectedTarget, animatedAction.getAnimationImageId(), imageInfoReader));
                }
            }
        }
    }
}

19 View Complete Implementation : AdjustPricesGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private Prices calculatePrices(WorldObject performer, World world) {
    Prices prices = performer.getProperty(Constants.PRICES);
    Prices newPrices = prices.copy();
    OperationInfo lastOperationInfo = world.getHistory().getLastPerformedOperation(performer);
    if (lastOperationInfo != null && lastOperationInfo.getManagedOperation() == Actions.BUY_ACTION) {
        int itemIndex = lastOperationInfo.getArgs()[3];
        Item item = Item.value(itemIndex);
        int buyPrice = lastOperationInfo.getArgs()[1];
        newPrices.setPrice(item, buyPrice + 1);
    }
    return newPrices;
}

19 View Complete Implementation : WorldPanel.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private void showTargetHitPoints(Graphics g) {
    OperationInfo lastPerformedOperation = world.getHistory().getLastPerformedOperation(playerCharacter);
    if (lastPerformedOperation != null) {
        WorldObject target = lastPerformedOperation.getTarget();
        if (target.hasProperty(Constants.HIT_POINTS) && world.exists(target) && !target.equals(playerCharacter)) {
            target = world.findWorldObjectById(target.getProperty(Constants.ID));
            int targetX = target.getProperty(Constants.X);
            int targetY = target.getProperty(Constants.Y);
            g.setColor(Color.RED);
            int x = (targetX + offsetX) * 48;
            int y = (targetY + offsetY) * 48;
            float percentageHitPointsLeft = (100f * target.getProperty(Constants.HIT_POINTS)) / target.getProperty(Constants.HIT_POINTS_MAX);
            int lineLength = (int) (48 * (percentageHitPointsLeft / 100));
            g.drawLine(x, y, x + lineLength, y);
        }
    }
}

19 View Complete Implementation : ImmediateGoalConversation.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public List<Response> getReplyPhrases(ConversationContext conversationContext) {
    WorldObject target = conversationContext.getTarget();
    World world = conversationContext.getWorld();
    Goal goal = world.getGoal(target);
    OperationInfo operationInfo = world.getImmediateGoal(target, world);
    String immediateGoalDescription = (operationInfo != null ? operationInfo.getDescription(world) : "");
    final Object goalDescription;
    if (goal != null) {
        goalDescription = goal.getDescription();
    } else {
        goalDescription = new FormattableText(TextId.GOAL_DOING_NOTHING);
    }
    return Arrays.asList(new Response(YES, TextId.ANSWER_IMMEDIATE_GOAL_YES, immediateGoalDescription, goalDescription), new Response(NO, TextId.ANSWER_IMMEDIATE_GOAL_NO));
}

19 View Complete Implementation : HistoryImpl.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private void addAsLastPerformedOperation(OperationInfo operationInfo) {
    int performerId = operationInfo.getPerformer().getProperty(Constants.ID).intValue();
    lastPerformedOperationMap.put(performerId, operationInfo);
}

19 View Complete Implementation : FurnitureGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private OperationInfo pureplacedemIntoHouse(WorldObject performer, int indexOfFurniture, WorldObject house, World world) {
    OperationInfo avoidTrappedContainer = ContainerUtils.avoidTrappedContainer(performer, house, world);
    if (avoidTrappedContainer != null) {
        return avoidTrappedContainer;
    }
    if (LockUtils.performerCanAccessContainer(performer, house)) {
        return new OperationInfo(performer, house, new int[] { indexOfFurniture }, Actions.PUT_ITEM_INTO_INVENTORY_ACTION);
    } else {
        // TODO: how to handle own house is locked?
        return null;
    }
}

19 View Complete Implementation : UTestConversations.java
Copyright GNU General Public License v3.0
Author : WorldGrower
public clreplaced UTestConversations {

    private Conversations conversations = new Conversations();

    private WorldObject performer = TestUtils.createWorldObject(1, "test1");

    private WorldObject target = TestUtils.createWorldObject(1, "test2");

    private World world = new WorldImpl(10, 10, null, null);

    private OperationInfo operationInfo = new OperationInfo(performer, target, Args.EMPTY, Actions.MELEE_ATTACK_ACTION);

    @Test
    public void testCreateArgs() {
        replacedertArrayEquals(new int[] { 0, -1, -1, 0, 0 }, Conversations.createArgs(Conversations.NAME_CONVERSATION));
        replacedertArrayEquals(new int[] { 0, 2, -1, 0, 0 }, Conversations.createArgs(Conversations.NAME_CONVERSATION, TestUtils.createWorldObject(2, "testworldobject")));
        replacedertArrayEquals(new int[] { 0, -1, 3, 0, 0 }, Conversations.createArgs(Conversations.NAME_CONVERSATION, new HistoryItem(3, operationInfo, new Turn(), null, null)));
    }

    @Test
    public void testGetQuestionPhrase() {
        String questionPhrase = conversations.getQuestionPhrase(0, -1, -1, performer, target, world, DefaultConversationFormatter.FORMATTER);
        replacedertEquals("What is your name?", questionPhrase);
    }

    @Test
    public void testGetReplyPhrase() {
        Response response = conversations.getReplyPhrase(0, -1, -1, performer, target, world, 0, 0);
        replacedertEquals(0, response.getId());
        replacedertEquals(-1, response.getSubjectId());
        replacedertEquals(-1, response.getHistoryItemId());
        replacedertEquals(true, response.isPossible());
        replacedertEquals("My name is test2", response.getResponsePhrase(DefaultConversationFormatter.FORMATTER));
    }
}

19 View Complete Implementation : GatherFoodGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private int calculateDistanceToMeatSource(WorldObject performer, OperationInfo butcherOperationInfo) {
    final int distanceToMeatSource;
    if (butcherOperationInfo != null) {
        distanceToMeatSource = Reach.distance(performer, butcherOperationInfo.getTarget());
    } else {
        distanceToMeatSource = Integer.MAX_VALUE;
    }
    return distanceToMeatSource;
}

19 View Complete Implementation : UTestGoalUtils.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Test
public void testCreateOperationInfoTarget() {
    World world = createWorld();
    WorldObject performer = TestUtils.createWorldObject(2, 2, 1, 1, Constants.ID, 7);
    int treeId = PlantGenerator.generateOldTree(5, 5, world);
    OperationInfo operationInfo = GoalUtils.createOperationInfo(performer, Actions.CUT_WOOD_ACTION, Args.EMPTY, world);
    replacedertEquals(Actions.CUT_WOOD_ACTION, operationInfo.getManagedOperation());
    replacedertEquals(treeId, operationInfo.getTarget().getProperty(Constants.ID).intValue());
}

19 View Complete Implementation : BackgroundImpl.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private void handlePerformerWasAttacked(WorldObject backgroundPerformer, OperationInfo operationInfo) {
    PerformerWasAttacked performerWasAttacked = new PerformerWasAttacked(backgroundPerformer);
    if (operationInfo.evaluate(performerWasAttacked) && !DefaultGoalObstructedHandler.isLegallyFighting(backgroundPerformer, operationInfo.getTarget(), operationInfo.getManagedOperation())) {
        revengeTargets.add(operationInfo.getPerformer().getProperty(Constants.ID));
    }
}

19 View Complete Implementation : ImmediateGoalConversation.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public Response getReplyPhrase(ConversationContext conversationContext) {
    WorldObject target = conversationContext.getTarget();
    World world = conversationContext.getWorld();
    final int replyId;
    Goal goal = world.getGoal(target);
    OperationInfo operationInfo = world.getImmediateGoal(target, world);
    if ((goal != null) && (operationInfo != null)) {
        replyId = YES;
    } else {
        replyId = NO;
    }
    return getReply(getReplyPhrases(conversationContext), replyId);
}

19 View Complete Implementation : AbstractSellGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public final OperationInfo calculateGoal(WorldObject performer, World world) {
    OperationInfo sellOperationInfo = BuySellUtils.getSellOperationInfo(performer, world, distance);
    if (sellOperationInfo != null) {
        return sellOperationInfo;
    } else {
        return null;
    }
}

19 View Complete Implementation : BrawlConversation.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public List<Response> getReplyPhrases(ConversationContext conversationContext) {
    WorldObject target = conversationContext.getTarget();
    World world = conversationContext.getWorld();
    OperationInfo immediateGoal = world.getImmediateGoal(target, world);
    final String immediateGoalDescription;
    if (immediateGoal != null) {
        immediateGoalDescription = immediateGoal.getDescription(world);
    } else {
        immediateGoalDescription = "resting";
    }
    return Arrays.asList(new Response(YES, TextId.ANSWER_BRAWL_YES), new Response(NO, TextId.ANSWER_BRAWL_NO), new Response(LATER, TextId.ANSWER_BRAWL_LATER, immediateGoalDescription), new Response(NOT_ENOUGH_GOLD, TextId.ANSWER_BRAWL_NOT_ENOUGH_GOLD), new Response(GET_LOST, TextId.ANSWER_BRAWL_GET_LOST));
}

19 View Complete Implementation : RepairHammerGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    OperationInfo buyOperationInfo = BuySellUtils.getBuyOperationInfo(performer, Constants.REPAIR_QUALITY, QUANreplacedY_TO_BUY, world);
    if (buyOperationInfo != null) {
        return buyOperationInfo;
    } else {
        return Goals.CREATE_REPAIR_HAMMER_GOAL.calculateGoal(performer, world);
    }
}

18 View Complete Implementation : CreateOrPlantWoodGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    OperationInfo createWoodOperationInfo = Goals.CREATE_WOOD_GOAL.calculateGoal(performer, world);
    if (createWoodOperationInfo != null && Reach.distance(performer, createWoodOperationInfo.getTarget()) < 11) {
        return createWoodOperationInfo;
    } else {
        WorldObject target = BuildLocationUtils.findOpenLocationNearExistingProperty(performer, BuildingDimensions.TREE, world, TerrainResource.WOOD);
        if (target != null) {
            return new OperationInfo(performer, target, Args.EMPTY, Actions.PLANT_TREE_ACTION);
        }
    }
    return null;
}

18 View Complete Implementation : CreateSleepingPotionGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    Integer apothecaryId = BuildingGenerator.getApothecaryId(performer);
    if (!Actions.BREW_SLEEPING_POTION_ACTION.hasEnoughNightShade(performer)) {
        OperationInfo harvestNightShadeGoal = Goals.HARVEST_NIGHT_SHADE_GOAL.calculateGoal(performer, world);
        if (harvestNightShadeGoal != null && Reach.distance(performer, harvestNightShadeGoal.getTarget()) < 15) {
            return harvestNightShadeGoal;
        }
        return Goals.PLANT_NIGHT_SHADE_GOAL.calculateGoal(performer, world);
    } else if (apothecaryId == null) {
        return Goals.APOTHECARY_GOAL.calculateGoal(performer, world);
    } else {
        WorldObject apothecary = world.findWorldObjectById(apothecaryId);
        return new OperationInfo(performer, apothecary, Args.EMPTY, Actions.BREW_SLEEPING_POTION_ACTION);
    }
}

18 View Complete Implementation : CurseKissGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    OperationInfo operationInfo = GoalUtils.createOperationInfo(performer, Actions.TALK_ACTION, Conversations.createArgs(Conversations.EXPLAIN_CURSE_CONVERSATION), world);
    if (operationInfo != null) {
        return operationInfo;
    }
    return null;
}

18 View Complete Implementation : EquipmentGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    WorldObjectContainer inventory = performer.getProperty(Constants.INVENTORY);
    int ironClaymoreCount = inventory.getWorldObjects(Constants.EQUIPMENT_SLOT, Constants.LEFT_HAND_EQUIPMENT).size();
    int ironCuirreplacedCount = inventory.getWorldObjects(Constants.EQUIPMENT_SLOT, Constants.TORSO_EQUIPMENT).size();
    int ironHelmetCount = inventory.getWorldObjects(Constants.EQUIPMENT_SLOT, Constants.HEAD_EQUIPMENT).size();
    int ironGauntletsCount = inventory.getWorldObjects(Constants.EQUIPMENT_SLOT, Constants.ARMS_EQUIPMENT).size();
    int ironBootsCount = inventory.getWorldObjects(Constants.EQUIPMENT_SLOT, Constants.FEET_EQUIPMENT).size();
    OperationInfo equipOperationInfo = Goals.USE_EQUIPMENT_GOAL.calculateGoal(performer, world);
    if (equipOperationInfo != null) {
        return equipOperationInfo;
    } else if (ironClaymoreCount == 0) {
        return getEquipment(performer, Item.IRON_CLAYMORE, world);
    } else if (UseEquipmentGoal.hasUnusedEquipment(performer, Constants.LEFT_HAND_EQUIPMENT)) {
        return UseEquipmentGoal.equipUnusedEquipment(performer, Constants.LEFT_HAND_EQUIPMENT, world);
    } else if (ironCuirreplacedCount == 0) {
        return getEquipment(performer, Item.IRON_CUIRreplaced, world);
    } else if (ironHelmetCount == 0) {
        return getEquipment(performer, Item.IRON_HELMET, world);
    } else if (ironGauntletsCount == 0) {
        return getEquipment(performer, Item.IRON_GAUNTLETS, world);
    } else if (ironBootsCount == 0) {
        return getEquipment(performer, Item.IRON_BOOTS, world);
    } else {
        return null;
    }
}

18 View Complete Implementation : EquipmentGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private OperationInfo getEquipment(WorldObject performer, Item item, World world) {
    // TODO: buy items should work with light/heavy armor
    OperationInfo buyOperationInfo = BuySellUtils.getBuyOperationInfo(performer, item, 1, world);
    if (buyOperationInfo != null) {
        return buyOperationInfo;
    } else {
        if (craftHeavyArmor(performer)) {
            return Goals.CRAFT_EQUIPMENT_GOAL.calculateGoal(performer, world);
        } else {
            return Goals.WEAVE_CLOTHES_GOAL.calculateGoal(performer, world);
        }
    }
}

18 View Complete Implementation : GatherFoodGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    WorldObject target = GoalUtils.findNearestTarget(performer, Actions.HARVEST_FOOD_ACTION, world);
    OperationInfo butcherOperationInfo = createButcherOperationInfo(performer, world);
    int distanceToMeatSource = calculateDistanceToMeatSource(performer, butcherOperationInfo);
    int distanceToFoodSource = calculateDistanceToFoodSource(performer, target);
    // System.out.println("distanceToFoodSource=" + distanceToFoodSource + "distanceToMeatSource=" + distanceToMeatSource);
    if (target != null && distanceToFoodSource < 15 && distanceToFoodSource < distanceToMeatSource) {
        return new OperationInfo(performer, target, Args.EMPTY, Actions.HARVEST_FOOD_ACTION);
    } else if (butcherOperationInfo != null && distanceToMeatSource < 15 && distanceToMeatSource < distanceToFoodSource) {
        return butcherOperationInfo;
    } else {
        return Goals.CREATE_FOOD_SOURCES_GOAL.calculateGoal(performer, world);
    }
}

18 View Complete Implementation : GetHealedGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    WorldObjectContainer performerInventory = performer.getProperty(Constants.INVENTORY);
    if (performerInventory.getQuanreplacedyFor(Constants.HIT_POINTS_HEALED) > 0) {
        int index = performerInventory.getIndexFor(Constants.HIT_POINTS_HEALED);
        return new OperationInfo(performer, performer, new int[] { index }, Actions.DRINK_FROM_INVENTORY_ACTION);
    } else if (MagicSpellUtils.canCast(performer, Actions.MINOR_HEAL_ACTION)) {
        if (Actions.MINOR_HEAL_ACTION.hasRequiredEnergy(performer)) {
            return new OperationInfo(performer, performer, Args.EMPTY, Actions.MINOR_HEAL_ACTION);
        } else {
            return Goals.REST_GOAL.calculateGoal(performer, world);
        }
    } else {
        OperationInfo buyHealingPotionOperationInfo = BuySellUtils.getBuyOperationInfo(performer, Constants.HIT_POINTS_HEALED, QUANreplacedY_TO_BUY, world);
        if (buyHealingPotionOperationInfo != null) {
            return buyHealingPotionOperationInfo;
        }
        List<WorldObject> targets = GoalUtils.findNearestTargetsByProperty(performer, Actions.TALK_ACTION, Constants.STRENGTH, w -> isTargetForMinorHealConversation(performer, w, world), world);
        if (targets.size() > 0) {
            return new OperationInfo(performer, targets.get(0), Conversations.createArgs(Conversations.MINOR_HEAL_CONVERSATION), Actions.TALK_ACTION);
        }
    }
    return null;
}

18 View Complete Implementation : GetPoisonCuredGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    WorldObjectContainer performerInventory = performer.getProperty(Constants.INVENTORY);
    if (performerInventory.getQuanreplacedyFor(Constants.CURE_POISON) > 0) {
        int index = performerInventory.getIndexFor(Constants.CURE_POISON);
        return new OperationInfo(performer, performer, new int[] { index }, Actions.DRINK_FROM_INVENTORY_ACTION);
    } else if (MagicSpellUtils.canCast(performer, Actions.CURE_POISON_ACTION)) {
        if (Actions.CURE_POISON_ACTION.hasRequiredEnergy(performer)) {
            return new OperationInfo(performer, performer, Args.EMPTY, Actions.CURE_POISON_ACTION);
        } else {
            return Goals.REST_GOAL.calculateGoal(performer, world);
        }
    } else {
        OperationInfo buyCurePoisonPotionOperationInfo = BuySellUtils.getBuyOperationInfo(performer, Constants.CURE_POISON, QUANreplacedY_TO_BUY, world);
        if (buyCurePoisonPotionOperationInfo != null) {
            return buyCurePoisonPotionOperationInfo;
        }
        List<WorldObject> targets = GoalUtils.findNearestTargetsByProperty(performer, Actions.TALK_ACTION, Constants.STRENGTH, w -> isTargetForCurePoisonConversation(performer, w, world), world);
        if (targets.size() > 0) {
            return new OperationInfo(performer, targets.get(0), Conversations.createArgs(Conversations.CURE_POISON_CONVERSATION), Actions.TALK_ACTION);
        }
    }
    return null;
}

18 View Complete Implementation : SocializeGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    List<WorldObject> targets = GoalUtils.findNearestNewTargets(performer, Actions.TALK_ACTION, Conversations.createArgs(Conversations.NAME_CONVERSATION), w -> isFirstTimeSocializeTargetForPerformer(performer, w), world);
    if (targets.size() > 0) {
        return new OperationInfo(performer, targets.get(0), Conversations.createArgs(Conversations.NAME_CONVERSATION), Actions.TALK_ACTION);
    } else {
        targets = GoalUtils.findNearestNewTargets(performer, Actions.TALK_ACTION, Conversations.createArgs(Conversations.PROFESSION_CONVERSATION), w -> isSocializeTargetForPerformer(performer, w), world);
        if (targets.size() > 0) {
            return new OperationInfo(performer, targets.get(0), Conversations.createArgs(Conversations.PROFESSION_CONVERSATION), Actions.TALK_ACTION);
        } else {
            targets = GoalUtils.findNearestNewTargets(performer, Actions.TALK_ACTION, Conversations.createArgs(Conversations.FAMILY_CONVERSATION), w -> isSocializeTargetForPerformer(performer, w), world);
            if (targets.size() > 0) {
                return new OperationInfo(performer, targets.get(0), Conversations.createArgs(Conversations.FAMILY_CONVERSATION), Actions.TALK_ACTION);
            } else {
                targets = GoalUtils.findNearestNewTargets(performer, Actions.TALK_ACTION, Conversations.createArgs(Conversations.DEITY_CONVERSATION), w -> isSocializeTargetForPerformer(performer, w), world);
                if (targets.size() > 0) {
                    return new OperationInfo(performer, targets.get(0), Conversations.createArgs(Conversations.DEITY_CONVERSATION), Actions.TALK_ACTION);
                } else {
                    OperationInfo shareKnowledgeOperationInfo = getShareKnowledgeOperationInfo(performer, world);
                    if (shareKnowledgeOperationInfo != null) {
                        return shareKnowledgeOperationInfo;
                    }
                }
            }
        }
    }
    return null;
}

18 View Complete Implementation : SoulGemGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    OperationInfo buyOperationInfo = BuySellUtils.getBuyOperationInfo(performer, Constants.SOUL_GEM, QUANreplacedY_TO_BUY, world);
    if (buyOperationInfo != null) {
        return buyOperationInfo;
    } else {
        return Goals.MINE_SOUL_GEMS_GOAL.calculateGoal(performer, world);
    }
}

18 View Complete Implementation : StandStillToTalkGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private boolean worldObjectTalkedWithPerformer(WorldObject performer, WorldObject w, World world) {
    OperationInfo lastPerformedOperation = world.getHistory().getLastPerformedOperation(w);
    if (lastPerformedOperation != null) {
        return lastPerformedOperation.getManagedOperation() == Actions.TALK_ACTION && lastPerformedOperation.getTarget().equals(performer);
    } else {
        return false;
    }
}

18 View Complete Implementation : StandStillToTalkGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private boolean movedLastTurn(WorldObject performer, World world) {
    OperationInfo lastPerformedOperation = world.getHistory().getLastPerformedOperation(performer);
    if (lastPerformedOperation != null) {
        ManagedOperation lastPerformedAction = lastPerformedOperation.getManagedOperation();
        return (lastPerformedAction == Actions.MOVE_ACTION) || (lastPerformedAction == Actions.STAND_STILL_TO_TALK_ACTION);
    } else {
        return false;
    }
}

18 View Complete Implementation : WoodGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    OperationInfo buyOperationInfo = BuySellUtils.getBuyOperationInfo(performer, Constants.WOOD, QUANreplacedY_TO_BUY, world);
    if (buyOperationInfo != null) {
        return buyOperationInfo;
    } else {
        return Goals.CREATE_WOOD_GOAL.calculateGoal(performer, world);
    }
}

18 View Complete Implementation : GoToPainter.java
Copyright GNU General Public License v3.0
Author : WorldGrower
public void setGotoOperations(WorldObject worldObject, List<OperationInfo> operationInfos) {
    gotoLocations.clear();
    Point currentPosition = new Point(worldObject.getProperty(Constants.X), worldObject.getProperty(Constants.Y));
    for (OperationInfo operationInfo : operationInfos) {
        if (operationInfo.getArgs().length == 2) {
            int newX = currentPosition.x + operationInfo.getArgs()[0];
            int newY = currentPosition.y + operationInfo.getArgs()[1];
            currentPosition = new Point(newX, newY);
            gotoLocations.add(currentPosition);
        }
    }
}

18 View Complete Implementation : UTestBecomeProfessionsOrganizationMemberGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Test
public void testCalculateGoalCandidateCreateProfessionOrganizationForTrickster() {
    World world = new WorldImpl(10, 10, null, null);
    WorldObject organization = GroupPropertyUtils.createProfessionOrganization(null, "TestOrg", Professions.FARMER_PROFESSION, world);
    WorldObject performer = createCommoner(world, organization);
    performer.setProperty(Constants.PROFESSION, Professions.TRICKSTER_PROFESSION);
    ChooseProfessionAction.createTricksterFacade(performer);
    replacedertEquals(Arrays.asList(0), performer.getProperty(Constants.GROUP).getIds());
    replacedertEquals(Actions.CREATE_PROFESSION_ORGANIZATION_ACTION, goal.calculateGoal(performer, world).getManagedOperation());
    OperationInfo operationInfo = goal.calculateGoal(performer, world);
    operationInfo.perform(world);
    replacedertEquals(Arrays.asList(0, 2), performer.getProperty(Constants.GROUP).getIds());
    replacedertEquals(Professions.WIZARD_PROFESSION, world.findWorldObjectById(2).getProperty(Constants.PROFESSION));
    replacedertEquals(true, goal.isGoalMet(performer, world));
}

18 View Complete Implementation : DeityAttributes.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private WorshipActionStatistics worshipActionStatistics(World world) {
    WorshipActionStatistics worshipActionStatistics = new WorshipActionStatistics();
    int totalWorshipActions = 0;
    Collection<OperationInfo> allLastPerformedOperations = world.getHistory().getAllLastPerformedOperations();
    for (OperationInfo operationInfo : allLastPerformedOperations) {
        if (operationInfo.getManagedOperation() == Actions.WORSHIP_DEITY_ACTION) {
            Deity deity = operationInfo.getPerformer().getProperty(Constants.DEITY);
            worshipActionStatistics.incrementWorshipCount(deity);
        }
    }
    worshipActionStatistics.setTotalWorshipActions(totalWorshipActions);
    return worshipActionStatistics;
}

18 View Complete Implementation : CattleOnTurn.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private void checkLeash(WorldObject worldObject, World world) {
    Integer leashId = worldObject.getProperty(Constants.LEASH_ID);
    if (leashId != null) {
        WorldObject leashOwner = world.findWorldObjectById(leashId);
        TaskCalculator taskCalculator = new TaskCalculatorImpl(world);
        OperationInfo meleeAttackOperationInfo = new OperationInfo(worldObject, leashOwner, Args.EMPTY, Actions.MELEE_ATTACK_ACTION);
        List<OperationInfo> tasks = taskCalculator.calculateTask(worldObject, world, meleeAttackOperationInfo);
        if (tasks.size() > 1) {
            OperationInfo moveOperationInfo = tasks.get(0);
            int newX = worldObject.getProperty(Constants.X) + moveOperationInfo.getArgs()[0];
            int newY = worldObject.getProperty(Constants.Y) + moveOperationInfo.getArgs()[1];
            LocationPropertyUtils.updateLocation(worldObject, newX, newY, world);
        }
    }
}

18 View Complete Implementation : CottonGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    OperationInfo harvestCottonOperationInfo = Goals.HARVEST_COTTON_GOAL.calculateGoal(performer, world);
    List<WorldObject> targets = BuySellUtils.findBuyTargets(performer, Constants.COTTON, QUANreplacedY_TO_BUY, world);
    if (targets.size() > 0) {
        return BuySellUtils.create(performer, targets.get(0), Item.COTTON, QUANreplacedY_TO_BUY, world);
    } else if (harvestCottonOperationInfo != null) {
        return harvestCottonOperationInfo;
    } else {
        WorldObject buildLocation = BuildLocationUtils.findOpenLocationNearExistingProperty(performer, BuildingDimensions.COTTON_PLANT, world, TerrainResource.COTTON);
        if (buildLocation != null) {
            return new OperationInfo(performer, buildLocation, Args.EMPTY, Actions.PLANT_COTTON_PLANT_ACTION);
        } else {
            return null;
        }
    }
}

18 View Complete Implementation : CreateHealingPotionGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    Integer apothecaryId = BuildingGenerator.getApothecaryId(performer);
    if (!Actions.BREW_HEALING_POTION_ACTION.hasEnoughNightShade(performer)) {
        OperationInfo harvestNightShadeOperationInfo = Goals.HARVEST_NIGHT_SHADE_GOAL.calculateGoal(performer, world);
        if (harvestNightShadeOperationInfo != null) {
            return harvestNightShadeOperationInfo;
        } else {
            return Goals.PLANT_NIGHT_SHADE_GOAL.calculateGoal(performer, world);
        }
    } else if (apothecaryId == null) {
        return Goals.APOTHECARY_GOAL.calculateGoal(performer, world);
    } else {
        WorldObject apothecary = world.findWorldObjectById(apothecaryId);
        return new OperationInfo(performer, apothecary, Args.EMPTY, Actions.BREW_HEALING_POTION_ACTION);
    }
}

17 View Complete Implementation : CreatePoisonGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    Integer apothecaryId = BuildingGenerator.getApothecaryId(performer);
    if (!Actions.BREW_POISON_ACTION.hasEnoughNightShade(performer)) {
        OperationInfo harvestNightShadeOperationInfo = Goals.HARVEST_NIGHT_SHADE_GOAL.calculateGoal(performer, world);
        if (harvestNightShadeOperationInfo != null) {
            return harvestNightShadeOperationInfo;
        } else {
            WorldObject target = BuildLocationUtils.findOpenLocationNearExistingProperty(performer, BuildingDimensions.NIGHT_SHADE, world);
            if (target != null) {
                return new OperationInfo(performer, target, Args.EMPTY, Actions.PLANT_NIGHT_SHADE_ACTION);
            } else {
                return null;
            }
        }
    } else if (apothecaryId == null) {
        return Goals.APOTHECARY_GOAL.calculateGoal(performer, world);
    } else {
        WorldObject apothecary = world.findWorldObjectById(apothecaryId);
        return new OperationInfo(performer, apothecary, Args.EMPTY, Actions.BREW_POISON_ACTION);
    }
}

17 View Complete Implementation : FoodGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
private OperationInfo acquireFood(WorldObject performer, World world) {
    OperationInfo buyOperationInfo = BuySellUtils.getBuyOperationInfo(performer, Constants.FOOD, QUANreplacedY_TO_BUY, world);
    if (buyOperationInfo != null) {
        return buyOperationInfo;
    } else {
        List<WorldObject> butcherTargets = GoalUtils.findNearestTargetsByProperty(performer, Actions.BUTCHER_ACTION, Constants.MEAT_SOURCE, w -> !CattlePropertyUtils.isOwnedCattle(w) && CattleOnTurn.cattleIsFullyGrown(w), world);
        if (butcherTargets.size() > 0 && Reach.distance(performer, butcherTargets.get(0)) < BUTCHER_DISTANCE) {
            return new OperationInfo(performer, butcherTargets.get(0), Args.EMPTY, Actions.BUTCHER_ACTION);
        } else {
            List<WorldObject> eatTargets = GoalUtils.findNearestTargetsByProperty(performer, Actions.EAT_ACTION, Constants.FOOD_SOURCE, w -> true, world);
            if (eatTargets.size() > 0 && Reach.distance(performer, eatTargets.get(0)) < FOOD_EAT_DISTANCE) {
                return new OperationInfo(performer, eatTargets.get(0), Args.EMPTY, Actions.EAT_ACTION);
            } else {
                return Goals.CREATE_FOOD_SOURCES_GOAL.calculateGoal(performer, world);
            }
        }
    }
}

17 View Complete Implementation : GetDiseaseCuredGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    WorldObjectContainer performerInventory = performer.getProperty(Constants.INVENTORY);
    if (performerInventory.getQuanreplacedyFor(Constants.CURE_DISEASE) > 0) {
        int index = performerInventory.getIndexFor(Constants.CURE_DISEASE);
        return new OperationInfo(performer, performer, new int[] { index }, Actions.DRINK_FROM_INVENTORY_ACTION);
    } else if (MagicSpellUtils.canCast(performer, Actions.CURE_DISEASE_ACTION)) {
        if (Actions.CURE_DISEASE_ACTION.hasRequiredEnergy(performer)) {
            return new OperationInfo(performer, performer, Args.EMPTY, Actions.CURE_DISEASE_ACTION);
        } else {
            return Goals.REST_GOAL.calculateGoal(performer, world);
        }
    } else {
        OperationInfo buyCureDiseasePotionOperationInfo = BuySellUtils.getBuyOperationInfo(performer, Constants.CURE_DISEASE, QUANreplacedY_TO_BUY, world);
        if (buyCureDiseasePotionOperationInfo != null) {
            return buyCureDiseasePotionOperationInfo;
        }
        List<WorldObject> targets = GoalUtils.findNearestTargetsByProperty(performer, Actions.TALK_ACTION, Constants.STRENGTH, w -> isTargetForCureDiseaseConversation(performer, w, world), world);
        if (targets.size() > 0) {
            return new OperationInfo(performer, targets.get(0), Conversations.createArgs(Conversations.CURE_DISEASE_CONVERSATION), Actions.TALK_ACTION);
        }
    }
    return null;
}

17 View Complete Implementation : MineResourcesGoal.java
Copyright GNU General Public License v3.0
Author : WorldGrower
@Override
public OperationInfo calculateGoal(WorldObject performer, World world) {
    WorldObjectContainer inventory = performer.getProperty(Constants.INVENTORY);
    if (inventory.getQuanreplacedyFor(Constants.STONE) < RESOURCE_CUTOFF) {
        OperationInfo mineOperationInfo = Goals.MINE_STONE_GOAL.calculateGoal(performer, world);
        if (mineOperationInfo != null) {
            return mineOperationInfo;
        }
    }
    if (inventory.getQuanreplacedyFor(Constants.ORE) < RESOURCE_CUTOFF) {
        OperationInfo mineOperationInfo = Goals.MINE_ORE_GOAL.calculateGoal(performer, world);
        if (mineOperationInfo != null) {
            return mineOperationInfo;
        }
    }
    if (inventory.getQuanreplacedyFor(Constants.GOLD) < RESOURCE_CUTOFF) {
        OperationInfo mineOperationInfo = Goals.MINE_GOLD_GOAL.calculateGoal(performer, world);
        if (mineOperationInfo != null) {
            return mineOperationInfo;
        }
    }
    return null;
}