Ejemplo n.º 1
0
        private void OnAnimalSpawnRequested(Transform obj)
        {
            // Someone requested an animal spawn, adjust to put it on top of ground
            obj.Position.Y = 100; // TODO: see @Utils.Spatial.PositionAboveGround
            var aboveGround = obj.Position.ToVector3().PositionAboveGround();

            obj.Position = aboveGround.Net();
            if (double.IsInfinity(obj.Position.Y))
            {
                Debug.LogWarning($"Someone requested an animal spawn outside map");
                return;
            }
            var packet = new Packet().Basic(obj.Position);

            obj.Id       = _nextId + 1;
            packet.Spawn = new Spawn
            {
                Animal = new Animal
                {
                    Transform = obj
                }
            };
            Debug.Log($"S1 requested animal spawn, approving at {obj.Position}");
            Mcm.instance.RpcAsync(packet);
            SpawnAnimal(aboveGround, obj.Rotation.ToQuaternion(),
                        Gm.instance.Experience.AnimalCharacteristics,
                        Gm.instance.Experience.AnimalCharacteristicsMinimumBound,
                        Gm.instance.Experience.AnimalCharacteristicsMaximumBound);
        }
Ejemplo n.º 2
0
        private void OnTransformUpdated(Transform obj) // TODO: merge spawn and update ?
        {
            if (!m_Animals.ContainsKey(obj.Id))
            {
                // Debug.LogError($"Tried to update in-existent animal {obj.Id}"); // TODO: maybe should pass client id
                return;
            }

            m_Animals[obj.Id].transform.position = obj.Position.ToVector3();
            m_Animals[obj.Id].transform.rotation = obj.Rotation.ToQuaternion();
        }
Ejemplo n.º 3
0
        private void DestroyTree(Transform obj)
        {
            if (!m_Trees.ContainsKey(obj.Id))
            {
                // Debug.LogError($"Tried to destroy in-existent tree {obj.Id}");
                return;
            }

            TreePool.instance.Despawn(m_Trees[obj.Id].gameObject);
            m_Trees.Remove(obj.Id);
        }
Ejemplo n.º 4
0
        private Vegetation SpawnTree(Transform obj)
        {
            m_NextId           = obj.Id;
            var(go, _)         = TreePool.instance.Spawn(obj.Position.ToVector3(), obj.Rotation.ToQuaternion());
            m_Trees[obj.Id]    = go.GetComponent <Vegetation>();
            m_Trees[obj.Id].id = obj.Id;

            if (SessionManager.instance.isServer)
            {
                m_Trees[obj.Id].BringToLife();
            }
            return(m_Trees[obj.Id]);
        }
Ejemplo n.º 5
0
 private void DestroyAnimal(Transform obj)
 {
     if (!m_Animals.ContainsKey(obj.Id))
     {
         // TODO: fix
         // Debug.LogError($"Tried to destroy in-existent animal {obj.Id}");
         return;
     }
     Pool.Despawn(m_Animals[obj.Id].gameObject);
     if (!m_Animals.Remove(obj.Id))
     {
         Debug.LogError($"Failed to remove animal {obj.Id}");
     }
 }
Ejemplo n.º 6
0
        private CommonAnimal SpawnAnimal(Transform obj)
        {
            // Debug.Log($"Spawning animal {obj}");
            m_NextId = obj.Id;
            var a = Pool.Spawn(animalPrefab, obj.Position.ToVector3(), obj.Rotation.ToQuaternion());

            m_Animals[obj.Id]    = a.GetComponent <CommonAnimal>();
            m_Animals[obj.Id].id = obj.Id;
            // Only server handle animal behaviours
            if (SessionManager.instance.isServer)
            {
                m_Animals[obj.Id].BringToLife();
                // var tSync = m_Animals[obj.Id].gameObject.AddComponent<TransformSync>();
                // tSync.id = obj.Id;
            }
            return(m_Animals[obj.Id]);
        }
Ejemplo n.º 7
0
        private void OnTreeSpawnRequested(Transform obj)
        {
            Debug.Log($"S1 requested tree spawn");
            // Someone requested a tree spawn, adjust to put it on top of ground
            obj.Position.Y = 1000; // TODO: see @Utils.Spatial.PositionAboveGround
            obj.Position   = obj.Position.ToVector3().PositionAboveGround().Net();
            var packet = new Packet().Basic(obj.Position);

            obj.Id       = ++m_NextId;
            packet.Spawn = new Spawn
            {
                Tree = new Api.Realtime.Tree
                {
                    Transform = obj
                }
            };
            MatchCommunicationManager.instance.RpcAsync(packet);
            SpawnTree(obj);
        }
Ejemplo n.º 8
0
        private void OnPlantSpawnRequested(Transform obj)
        {
            Debug.Log($"S1 requested tree spawn");
            // Someone requested a tree spawn, adjust to put it on top of ground
            obj.Position.Y = 1000; // TODO: see @Utils.Spatial.PositionAboveGround
            var aboveGround = obj.Position.ToVector3().PositionAboveGround();

            obj.Position = aboveGround.Net();
            var packet = new Packet().Basic(obj.Position);

            obj.Id       = _nextId + 1;
            packet.Spawn = new Spawn
            {
                Plant = new Api.Realtime.Plant
                {
                    Transform = obj
                }
            };
            Mcm.instance.RpcAsync(packet);
            SpawnPlant(aboveGround, obj.Rotation.ToQuaternion(),
                       Gm.instance.Experience.PlantCharacteristics,
                       Gm.instance.Experience.PlantCharacteristicsMinimumBound,
                       Gm.instance.Experience.PlantCharacteristicsMaximumBound);
        }
Ejemplo n.º 9
0
 private void OnTreeDestroyRequested(Transform obj) => throw new NotImplementedException();
Ejemplo n.º 10
0
 private void OnTreeDestroyed(Transform obj) => DestroyTree(obj);
Ejemplo n.º 11
0
 private void OnTreeSpawned(Transform obj) => SpawnTree(obj);
Ejemplo n.º 12
0
 private void OnAnimalDestroyed(Transform obj) => DestroyAnimal(obj);
Ejemplo n.º 13
0
 private void OnAnimalSpawned(Transform obj) => SpawnAnimal(obj);
Ejemplo n.º 14
0
 private void OnPlantDestroyed(Transform obj) => DestroyPlant(obj.Id);
Ejemplo n.º 15
0
 private void OnPlantSpawned(Transform obj) =>
 SpawnPlant(obj.Position.ToVector3(), obj.Rotation.ToQuaternion(),
            Gm.instance.Experience.PlantCharacteristics,
            Gm.instance.Experience.PlantCharacteristicsMinimumBound,
            Gm.instance.Experience.PlantCharacteristicsMaximumBound);