protected override void Execute(List <InputEntity> entities)
    {
        GameEntity[] selectedUnitProduction = selected.GetEntities();
        if (selectedUnitProduction.Length > 0)
        {
            GameEntity unitProductionBuilding = selectedUnitProduction[0];
            foreach (var entity in entities)
            {
                int price = DeterminePrice(entity.unitType.type);
                if (GameUtils.IsEnoughResource(gameContext, gameContext.playerInventory, GameResource.GOLD, price))
                {
                    GameEntity buildWorkerAction = gameContext.CreateEntity();
                    buildWorkerAction.AddChannelAction(5f);
                    buildWorkerAction.AddCountdown(5f);
                    buildWorkerAction.AddAction(false);
                    buildWorkerAction.AddParentLink(unitProductionBuilding.id.value);
                    buildWorkerAction.AddUnitType(entity.unitType.type);
                    buildWorkerAction.isCreateUnitAction = true;

                    GameEntity payResourcesAction = gameContext.CreateEntity();
                    payResourcesAction.AddTransferResourceAction(gameContext.playerInventory.resourceIndex[GameResource.GOLD],
                                                                 buildWorkerAction.id.value, price);
                    payResourcesAction.AddAction(false);
                    payResourcesAction.isAct = true;
                }
                else
                {
                    //TODO: Not enough warning
                }
            }
        }
    }
Beispiel #2
0
    public void Execute()
    {
        foreach (var entity in followObjects)
        {
            if (!entity.hasTargetLink)
            {
                continue;
            }

            GameEntity targetEntity = gameContext.GetEntityWithId(entity.targetLink.linkId);
            if (targetEntity != null)
            {
                float   distanceToTravel = Time.deltaTime * entity.follow.speed;
                Vector3 direction        = targetEntity.position.position - entity.position.position;
                if (direction.sqrMagnitude < distanceToTravel * distanceToTravel)
                {
                    entity.isDestroyed = true;
                    GameEntity damageAction = gameContext.CreateEntity();
                    damageAction.isAct = true;
                    damageAction.AddAction(false);
                    damageAction.AddDamageAction(entity.targetLink.linkId, 10f);
                }
                else
                {
                    Vector3 step = direction.normalized * distanceToTravel;
                    entity.ReplacePosition(entity.position.position + step);
                    entity.ReplaceRotation(Quaternion.FromToRotation(Vector3.forward, direction));
                }
            }
            else
            {
                entity.isDestroyed = true;
            }
        }
    }