Example #1
0
        /// <summary>
        /// Creates a clone of the agent at a bigger size and destroys the original.
        /// </summary>
        void IMoltable.Molt()
        {
            ITrait sizeTrait = (Agent as IStatsCollection).GetStat(TraitsUtil.sizeTraitId);

            int size = sizeTrait != null ? sizeTrait.Quantity : 0;

            // If the size is less than one, then simply destroy the agent without molting.
            if (size < 1)
            {
                GameObject.Destroy(AgentGameObject);
                return;
            }

            int newSize = (int)(size * moltPercentage);

            newSize            = Mathf.Max(newSize, size + 1);
            sizeTrait.Quantity = newSize;

            Vector3 scale = AgentTransform.localScale;

            scale *= moltPercentage;

            Vector3 position = Agent.Position;

            int health = TraitsUtil.GetHealth(Agent) + 1;

            Agent.RemoveFromMap();

            GameObject instance = spawnable.Spawn(position, scale);

            IAgent instanceAgent = instance.GetComponentInChildren <IAgent>();

            if (instanceAgent != null)
            {
                instanceAgent.Data        = Agent.Data.Copy();
                instanceAgent.DisplayName = Agent.DisplayName;
                instanceAgent.Description = "";
                instanceAgent.GroupId     = Agent.GroupId;
                TraitsUtil.SetHealth(instanceAgent, health);
            }

            Tweener tweener = instance.GetComponentInChildren <Tweener>();

            if (tweener != null)
            {
                tweener.TweenOnStart = TweenerMethod.None;
            }

            GameObject.Destroy(AgentGameObject);
        }