예제 #1
0
    public WorkerStateTrigger Collide(Collider collider, ref int health)
    {
        // When the master merger recieves a slave merger it returns it to pool,
        // until the number of leveling up is reached then it outputs
        // the trigger for the next state
        if (collider.CompareTag("SlaveMerger"))
        {
            ICollidable slaveMerger = collider.GetComponent <ICollidable>();
            health += slaveMerger.Gethealth();
            slaveMerger.ReactToCollision(0);
            mergedCount++;
            if (mergedCount == wc.workersPerLevel - 1)
            {
                m_meshChange.ChangeHelmet(wfsm.level + 1);
                m_meshChange.ChangeOveroll(wfsm.level + 1);
                mergedCount = 0;

                return(WorkerStateTrigger.StateEnd);
            }
        }
        return(WorkerStateTrigger.Null);
    }
예제 #2
0
    public override WorkerStateTrigger Collide(Collider collider, ref int health)
    {
        IObstacle collidableObstacle = collider.GetComponent <IObstacle>();

        // When a worker hits an obstacle it decreases his health by its health
        // and vice versa, if the worker loses all his health he dies
        if (collidableObstacle != null)
        {
            int obsHealth      = collidableObstacle.Gethealth();
            int preCollisionWH = health;
            health -= obsHealth;

            collidableObstacle.ReactToCollision(preCollisionWH);

            if (health <= 0)
            {
                collidableObstacle.PlayEffect(animator, rb, VestState.WithoutVest);
                return(WorkerStateTrigger.Die);
            }
            else
            {
                int workersHealthFrac = health % 5;
                health -= workersHealthFrac;
                WorkersManager.Instance.Descend(mState);

                mMeshChange.ChangeHelmet(mState.level);
                mMeshChange.ChangeOveroll(mState.level);

                Vector2 pos;
                for (int i = 1; i <= workersHealthFrac; i++)
                {
                    pos.x = Random.Range(mState.transform.position.x - 0.05f, mState.transform.position.x + 0.05f);
                    pos.y = Random.Range(mState.transform.position.z - 0.1f, mState.transform.position.z - 0.05f);
                    WorkersManager.Instance.AddWorker(pos);
                }
            }
        }
        return(WorkerStateTrigger.Null);
    }