Exemplo n.º 1
0
 void settargets()
 {
     foreach (GameObject a in players)
     {
         MovementForces mf = a.GetComponent <MovementForces>();
         mf.targets = zombies;
     }
     foreach (GameObject a in zombies)
     {
         MovementForces mf = a.GetComponent <MovementForces>();
         mf.targets = players;
     }
 }
Exemplo n.º 2
0
        void HandleMoveSetModMovementForceMagnitudeAck(MovementSpeedAck setModMovementForceMagnitudeAck)
        {
            Unit mover = _player.m_unitMovedByMe;

            Cypher.Assert(mover != null);                      // there must always be a mover
            _player.ValidateMovementInfo(setModMovementForceMagnitudeAck.Ack.Status);

            // prevent tampered movement data
            if (setModMovementForceMagnitudeAck.Ack.Status.Guid != mover.GetGUID())
            {
                Log.outError(LogFilter.Network, $"HandleSetModMovementForceMagnitudeAck: guid error, expected {mover.GetGUID()}, got {setModMovementForceMagnitudeAck.Ack.Status.Guid}");
                return;
            }

            // skip all except last
            if (_player.m_movementForceModMagnitudeChanges > 0)
            {
                --_player.m_movementForceModMagnitudeChanges;
                if (_player.m_movementForceModMagnitudeChanges == 0)
                {
                    float          expectedModMagnitude = 1.0f;
                    MovementForces movementForces       = mover.GetMovementForces();
                    if (movementForces != null)
                    {
                        expectedModMagnitude = movementForces.GetModMagnitude();
                    }

                    if (Math.Abs(expectedModMagnitude - setModMovementForceMagnitudeAck.Speed) > 0.01f)
                    {
                        Log.outDebug(LogFilter.Misc, $"Player {_player.GetName()} from account id {_player.GetSession().GetAccountId()} kicked for incorrect movement force magnitude (must be {expectedModMagnitude} instead {setModMovementForceMagnitudeAck.Speed})");
                        _player.GetSession().KickPlayer();
                        return;
                    }
                }
            }

            setModMovementForceMagnitudeAck.Ack.Status.Time += m_clientTimeDelay;

            MoveUpdateSpeed updateModMovementForceMagnitude = new MoveUpdateSpeed(ServerOpcodes.MoveUpdateModMovementForceMagnitude);

            updateModMovementForceMagnitude.Status = setModMovementForceMagnitudeAck.Ack.Status;
            updateModMovementForceMagnitude.Speed  = setModMovementForceMagnitudeAck.Speed;
            mover.SendMessageToSet(updateModMovementForceMagnitude, false);
        }
    // Use this for initialization
    void Start()
    {
        //is vehicle prototype assigned in editor?
        if (null == vehiclePrototype)
        {
            Debug.Log("Error in " + gameObject.name +
                      ": VehiclePrototype is not assigned.");
            Debug.Break();
        }
        //is target prototype assigned in editor?
        if (null == targetPrototype)
        {
            Debug.Log("Error in " + gameObject.name +
                      ": VehiclePrototype is not assigned.");
            Debug.Break();
        }
        //is terrain assigned in editor?
        if (null == terrain)
        {
            Debug.Log("Error in " + gameObject.name +
                      ": Terrain is not assigned.");
            Debug.Break();
        }
        //is the terrain assigned a terraingenerator component?
        terrainGenerator = terrain.GetComponent <TerrainGenerator>();
        if (null == terrainGenerator)
        {
            Debug.Log("Error in " + gameObject.name +
                      ": Terrain is required to have a TerrainGenerator script");
            Debug.Break();
        }

        //initialize this world size with the terrain generator world size
        worldSize = terrainGenerator.worldSize;

        //instantiate humans
        for (int i = 0; i < targetCount; i++)
        {
            // Add humans to the list
            targetList.Add(Instantiate(targetPrototype));

            //initialize target bounding sphere with target component
            targetBS = targetList[i].GetComponent <BoundingSphere>();

            //check if assigned
            if (null == targetBS)
            {
                Debug.Log("Error in " + gameObject.name +
                          ": TargetPrototype is required to have a Bounding Sphere script");
                Debug.Break();
            }

            //initialize movementForces with vehicle's component
            MovementForces targetMF = targetList[i].GetComponent <MovementForces>();
            if (null == targetMF)
            {
                Debug.Log("Error in " + gameObject.name +
                          ": TargetPrototype is required to have a MovementForces script");
                Debug.Break();
            }

            // Randomize human's inital position
            RandomizePosition(targetList[i]);
        }

        //instantiate zombies
        for (int i = 0; i < seekerCount; i++)
        {
            // Add zombies to the list
            seekerList.Add(Instantiate(vehiclePrototype));

            //initialize vehicle bounding sphere with vehicle component
            vehicleBS = seekerList[i].GetComponent <BoundingSphere>();
            //check is assigned
            if (null == vehicleBS)
            {
                Debug.Log("Error in " + gameObject.name +
                          ": VehiclePrototype is required to have a Bounding Sphere script");
                Debug.Break();
            }


            //initialize movementForces with vehicle's component
            MovementForces vehicleMF = seekerList[i].GetComponent <MovementForces>();
            if (null == vehicleMF)
            {
                Debug.Log("Error in " + gameObject.name +
                          ": VehiclePrototype is required to have a MovementForces script");
                Debug.Break();
            }

            // Randomize zombie's intial position
            RandomizePosition(seekerList[i]);
        }

        //instantiate obstacles
        for (int i = 0; i < obstCount; i++)
        {
            obstList.Add(Instantiate(obstPrototype));

            RandomizePosition(obstList [i]);
        }
    }