Ejemplo n.º 1
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar      playerAvatar       = level.GetPlayerAvatar();
            LogicGameObjectManager gameObjectManager  = level.GetGameObjectManager();
            LogicResourceData      repairResourceData = null;

            int repairCost = 0;

            for (int i = 0; i < this.m_gameObjectIds.Size(); i++)
            {
                LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]);

                if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.TRAP)
                {
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.IsDisarmed() && !trap.IsConstructing())
                    {
                        LogicTrapData data = trap.GetTrapData();

                        repairResourceData = data.GetBuildResource();
                        repairCost        += data.GetRearmCost(trap.GetUpgradeLevel());
                    }
                }
            }

            if (repairResourceData != null && repairCost != 0)
            {
                if (playerAvatar.HasEnoughResources(repairResourceData, repairCost, true, this, false))
                {
                    playerAvatar.CommodityCountChangeHelper(0, repairResourceData, -repairCost);

                    for (int i = 0; i < this.m_gameObjectIds.Size(); i++)
                    {
                        LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]);

                        if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.TRAP)
                        {
                            LogicTrap trap = (LogicTrap)gameObject;

                            if (trap.IsDisarmed() && !trap.IsConstructing())
                            {
                                trap.RepairTrap();
                            }
                        }
                    }

                    return(0);
                }

                return(-2);
            }

            return(-1);
        }