Ejemplo n.º 1
0
        public void Awake()
        {
            rateLimiter = new RateLimiter();
            creature    = gameObject.GetComponent <Creature>();
            if (creature != null)
            {
                actions = (List <CreatureAction>) typeof(Creature).GetField("actions", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(creature);
            }

            res = new ClientCreatureUpdate();
            res.creatureGuid = GuidHelper.Get(gameObject);
            res.tech         = CraftData.GetTechType(gameObject);
        }
Ejemplo n.º 2
0
        public void Correct(ClientCreatureUpdate msg)
        {
            if (Vector3.SqrMagnitude(transform.position - msg.position) > maxValidDistSq)
            {
                transform.position = msg.position;
                transform.rotation = msg.rotation;
            }

            if (creature != null)
            {
                creature.leashPosition = msg.leashPosition;
            }

            if (actions != null && msg.actionIndex >= 0 && msg.actionIndex < actions.Count)
            {
                var oldAction = creature.GetBestAction();
                var newAction = actions[msg.actionIndex];

                if (newAction != oldAction)
                {
                    if (oldAction != null)
                    {
                        oldAction.StopPerform(creature);
                    }

                    if (newAction != null)
                    {
                        newAction.StartPerform(creature);
                    }

                    prevActionField.SetValue(creature, newAction);
                }

                if (newAction != null)
                {
                    newAction.Perform(creature, Time.deltaTime);
                }
            }
        }
Ejemplo n.º 3
0
        private void Process(ClientCreatureUpdate msg)
        {
            var target = GuidHelper.Find(msg.creatureGuid, false);

            if (target == null)
            {
                if (LargeWorld.main == null)
                {
                    return;
                }

                if (Vector3.SqrMagnitude(Player.main.transform.position - msg.position) > SyncedCreature.maxSpawnDistSq)
                {
                    return;
                }

                var prefab = CraftData.GetPrefabForTechType(msg.tech, false);
                if (prefab == null)
                {
                    return;
                }

                target = UnityEngine.Object.Instantiate(prefab, msg.position, msg.rotation);
                GuidHelper.Set(target, msg.creatureGuid);
                var component = (LargeWorldEntity)target.AddComponent(typeof(LargeWorldEntity));
                component.cellLevel = LargeWorldEntity.CellLevel.Medium;

                LargeWorld.main.streamer.cellManager.RegisterEntity(component);
                target.SetActive(true);
            }

            var sync = (SyncedCreature)target.EnsureComponent(typeof(SyncedCreature));

            sync.ownership = false;
            sync.Correct(msg);
        }