Ejemplo n.º 1
0
        /// <summary>
        ///     Sets the gameobject position.
        /// </summary>
        public void SetPositionXY(int x, int y)
        {
            if (this._position.X != x || this._position.Y != y)
            {
                int oldX = this.GetTileX();
                int oldY = this.GetTileY();

                this._position.Set(x, y);

                if (this._components[13] != null)
                {
                    LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this._components[13];

                    if (layoutComponent.IsEnabled())
                    {
                        if (this._level != null)
                        {
                            layoutComponent.SetPositionLayout(this._level.GetActiveLayout(), x >> 9, y >> 9);
                        }
                    }
                }

                if (this._globalId != -1)
                {
                    this._level.GetTileMap().GameObjectMoved(this, oldX, oldY);
                }
            }
        }
        public virtual void SetInitialPosition(int x, int y)
        {
            this.m_position.Set(x, y);

            LogicLayoutComponent layoutComponent = this.GetLayoutComponent();

            if (layoutComponent != null && this.m_level != null)
            {
                layoutComponent.SetPositionLayout(this.m_level.GetActiveLayout(), x >> 9, y >> 9);
            }
        }
        public LogicVector2 GetPositionLayout(int layoutId, bool editMode)
        {
            LogicLayoutComponent layoutComponent = this.GetLayoutComponent();

            Debugger.DoAssert(layoutComponent != null, "LayoutComponent is null");

            if (editMode)
            {
                return(layoutComponent.GetEditModePositionLayout(layoutId));
            }

            return(layoutComponent.GetPositionLayout(layoutId));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Sets the initial position.
        /// </summary>
        public virtual void SetInitialPosition(int x, int y)
        {
            this._position.Set(x, y);

            if (this._components[13] != null)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this._components[13];

                if (layoutComponent.IsEnabled())
                {
                    if (this._level != null)
                    {
                        layoutComponent.SetPositionLayout(this._level.GetActiveLayout(), x >> 9, y >> 9);
                    }
                }
            }
        }
        public override void SaveToSnapshot(LogicJSONObject jsonObject, int layoutId)
        {
            if (this.m_upgLevel != 0 || this.m_constructionTimer == null || this.m_upgrading)
            {
                jsonObject.Put("lvl", new LogicJSONNumber(this.m_upgLevel));
            }
            else
            {
                jsonObject.Put("lvl", new LogicJSONNumber(-1));
            }

            if (this.m_constructionTimer != null)
            {
                jsonObject.Put("const_t", new LogicJSONNumber(this.m_constructionTimer.GetRemainingSeconds(this.m_level.GetLogicTime())));
            }

            LogicTrapData data = this.GetTrapData();

            if (data.HasAlternativeMode() || data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT);

                if (layoutComponent != null)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        jsonObject.Put(layoutComponent.GetLayoutVariableNameAirMode(i, false), new LogicJSONBoolean(this.m_useAirMode[i]));
                    }
                }
            }

            if (data.GetDirectionCount() > 0)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT);

                if (layoutComponent != null)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        jsonObject.Put(layoutComponent.GetLayoutVariableNameTrapDirection(i, false), new LogicJSONNumber(this.m_direction[i]));
                    }
                }
            }

            base.SaveToSnapshot(jsonObject, layoutId);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Sets the gameobject position in layout.
        /// </summary>
        public void SetPositionLayoutXY(int tileX, int tileY, int activeLayout, bool editMode)
        {
            if (this._components[13] != null)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this._components[13];

                if (layoutComponent.IsEnabled())
                {
                    if (editMode)
                    {
                        layoutComponent.SetEditModePositionLayout(activeLayout, tileX, tileY);
                    }
                    else
                    {
                        layoutComponent.SetPositionLayout(activeLayout, tileX, tileY);
                    }
                }
            }
        }
        public void SetPositionXY(int x, int y)
        {
            if (this.m_position.m_x != x || this.m_position.m_y != y)
            {
                int prevX = this.GetTileX();
                int prevY = this.GetTileY();

                this.m_position.Set(x, y);

                LogicLayoutComponent layoutComponent = this.GetLayoutComponent();

                if (layoutComponent != null)
                {
                    layoutComponent.SetPositionLayout(this.m_level.GetActiveLayout(), x >> 9, y >> 9);
                }

                if (this.m_globalId != 0)
                {
                    this.m_level.GetTileMap().GameObjectMoved(this, prevX, prevY);
                }
            }
        }
        public override void LoadFromSnapshot(LogicJSONObject jsonObject)
        {
            if (this.m_data.GetVillageType() == 1)
            {
                this.Load(jsonObject);
                return;
            }

            LogicTrapData data = this.GetTrapData();

            this.LoadUpgradeLevel(jsonObject);
            this.m_level.GetWorkerManagerAt(this.m_villageType).DeallocateWorker(this);

            if (this.m_constructionTimer != null)
            {
                this.m_constructionTimer.Destruct();
                this.m_constructionTimer = null;
            }

            if (data.HasAlternativeMode() || data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT);

                if (layoutComponent != null)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        LogicJSONBoolean airModeObject = jsonObject.GetJSONBoolean(layoutComponent.GetLayoutVariableNameAirMode(i, false));

                        if (airModeObject != null)
                        {
                            this.m_useAirMode[i] = airModeObject.IsTrue();
                        }
                    }
                }

                LogicTriggerComponent triggerComponent = this.GetTriggerComponent();

                bool airMode = this.m_useAirMode[this.m_level.GetWarLayout()];

                triggerComponent.SetAirTrigger(airMode);
                triggerComponent.SetGroundTrigger(!airMode);
            }

            if (data.GetDirectionCount() > 0)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT);

                if (layoutComponent != null)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        LogicJSONNumber trapDistanceObject = jsonObject.GetJSONNumber(layoutComponent.GetLayoutVariableNameTrapDirection(i, false));

                        if (trapDistanceObject != null)
                        {
                            this.m_direction[i] = trapDistanceObject.GetIntValue();
                        }
                    }
                }
            }

            this.m_level.GetWorkerManagerAt(this.m_data.GetVillageType()).DeallocateWorker(this);

            if (this.m_constructionTimer != null)
            {
                this.m_constructionTimer.Destruct();
                this.m_constructionTimer = null;
            }

            this.SetUpgradeLevel(this.m_upgLevel);
            base.LoadFromSnapshot(jsonObject);
        }
        public override void Load(LogicJSONObject jsonObject)
        {
            this.LoadUpgradeLevel(jsonObject);

            LogicTrapData data = this.GetTrapData();

            if (data.HasAlternativeMode() || data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT);

                if (layoutComponent != null)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        LogicJSONBoolean airModeObject = jsonObject.GetJSONBoolean(layoutComponent.GetLayoutVariableNameAirMode(i, false));

                        if (airModeObject != null)
                        {
                            this.m_useAirMode[i] = airModeObject.IsTrue();
                        }

                        LogicJSONBoolean draftAirModeObject = jsonObject.GetJSONBoolean(layoutComponent.GetLayoutVariableNameAirMode(i, true));

                        if (draftAirModeObject != null)
                        {
                            this.m_draftUseAirMode[i] = draftAirModeObject.IsTrue();
                        }
                    }
                }

                LogicTriggerComponent triggerComponent = this.GetTriggerComponent();

                int  layoutId = this.m_level.GetCurrentLayout();
                bool airMode  = this.m_useAirMode[layoutId];

                triggerComponent.SetAirTrigger(airMode);
                triggerComponent.SetGroundTrigger(!airMode);
            }

            if (data.GetDirectionCount() > 0)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT);

                if (layoutComponent != null)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        LogicJSONNumber trapDistanceObject = jsonObject.GetJSONNumber(layoutComponent.GetLayoutVariableNameTrapDirection(i, false));

                        if (trapDistanceObject != null)
                        {
                            this.m_direction[i] = trapDistanceObject.GetIntValue();
                        }

                        LogicJSONNumber draftTrapDistanceObject = jsonObject.GetJSONNumber(layoutComponent.GetLayoutVariableNameTrapDirection(i, true));

                        if (draftTrapDistanceObject != null)
                        {
                            this.m_draftDirection[i] = draftTrapDistanceObject.GetIntValue();
                        }
                    }
                }
            }

            this.m_level.GetWorkerManagerAt(this.m_villageType).DeallocateWorker(this);

            if (this.m_constructionTimer != null)
            {
                this.m_constructionTimer.Destruct();
                this.m_constructionTimer = null;
            }

            LogicJSONNumber constTimeObject = jsonObject.GetJSONNumber("const_t");

            if (constTimeObject != null)
            {
                int constTime = constTimeObject.GetIntValue();

                if (!LogicDataTables.GetGlobals().ClampBuildingTimes())
                {
                    if (this.m_upgLevel < data.GetUpgradeLevelCount() - 1)
                    {
                        constTime = LogicMath.Min(constTime, data.GetBuildTime(this.m_upgLevel + 1));
                    }
                }

                this.m_constructionTimer = new LogicTimer();
                this.m_constructionTimer.StartTimer(constTime, this.m_level.GetLogicTime(), false, -1);

                LogicJSONNumber constTimeEndObject = jsonObject.GetJSONNumber("const_t_end");

                if (constTimeEndObject != null)
                {
                    this.m_constructionTimer.SetEndTimestamp(constTimeEndObject.GetIntValue());
                }

                LogicJSONNumber conffObject = jsonObject.GetJSONNumber("con_ff");

                if (conffObject != null)
                {
                    this.m_constructionTimer.SetFastForward(conffObject.GetIntValue());
                }

                this.m_level.GetWorkerManagerAt(this.m_villageType).AllocateWorker(this);
                this.m_upgrading = this.m_upgLevel != -1;
            }

            LogicJSONBoolean disarmed = jsonObject.GetJSONBoolean("needs_repair");

            if (disarmed != null)
            {
                this.m_disarmed = disarmed.IsTrue();
            }

            this.SetUpgradeLevel(this.m_upgLevel);
            base.Load(jsonObject);
        }
Ejemplo n.º 10
0
        public override void Save(LogicJSONObject jsonObject, int villageType)
        {
            if (this.m_upgLevel != 0 || this.m_constructionTimer == null || this.m_upgrading)
            {
                jsonObject.Put("lvl", new LogicJSONNumber(this.m_upgLevel));
            }
            else
            {
                jsonObject.Put("lvl", new LogicJSONNumber(-1));
            }

            if (this.m_constructionTimer != null)
            {
                jsonObject.Put("const_t", new LogicJSONNumber(this.m_constructionTimer.GetRemainingSeconds(this.m_level.GetLogicTime())));

                if (this.m_constructionTimer.GetEndTimestamp() != -1)
                {
                    jsonObject.Put("const_t_end", new LogicJSONNumber(this.m_constructionTimer.GetEndTimestamp()));
                }

                if (this.m_constructionTimer.GetFastForward() != -1)
                {
                    jsonObject.Put("con_ff", new LogicJSONNumber(this.m_constructionTimer.GetFastForward()));
                }
            }

            if (this.m_disarmed && this.GetTrapData().GetVillageType() != 1)
            {
                jsonObject.Put("needs_repair", new LogicJSONBoolean(true));
            }

            LogicTrapData data = this.GetTrapData();

            if (data.HasAlternativeMode() || data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT);

                if (layoutComponent != null)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        jsonObject.Put(layoutComponent.GetLayoutVariableNameAirMode(i, false), new LogicJSONBoolean(this.m_useAirMode[i]));
                        jsonObject.Put(layoutComponent.GetLayoutVariableNameAirMode(i, true), new LogicJSONBoolean(this.m_draftUseAirMode[i]));
                    }
                }
            }

            if (data.GetDirectionCount() > 0)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT);

                if (layoutComponent != null)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        jsonObject.Put(layoutComponent.GetLayoutVariableNameTrapDirection(i, false), new LogicJSONNumber(this.m_direction[i]));
                        jsonObject.Put(layoutComponent.GetLayoutVariableNameTrapDirection(i, true), new LogicJSONNumber(this.m_draftDirection[i]));
                    }
                }
            }

            base.Save(jsonObject, villageType);
        }