Пример #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);
        }
Пример #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();
        }
Пример #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);
        }
Пример #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]);
        }
Пример #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}");
     }
 }
Пример #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]);
        }
Пример #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);
        }
Пример #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);
        }
Пример #9
0
 private void OnTreeDestroyRequested(Transform obj) => throw new NotImplementedException();
Пример #10
0
 private void OnTreeDestroyed(Transform obj) => DestroyTree(obj);
Пример #11
0
 private void OnTreeSpawned(Transform obj) => SpawnTree(obj);
Пример #12
0
 private void OnAnimalDestroyed(Transform obj) => DestroyAnimal(obj);
Пример #13
0
 private void OnAnimalSpawned(Transform obj) => SpawnAnimal(obj);
Пример #14
0
 private void OnPlantDestroyed(Transform obj) => DestroyPlant(obj.Id);
Пример #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);