// Start is called before the first frame update
    void Start()
    {
        if (id == null || id == "")
        {
            id = Guid.NewGuid().ToString();
        }
        if (worldState == null)
        {
            worldState    = new CharacterWorldState();
            worldState.Id = id;
        }
        ProtoClient.syncedCharacters.Add(this);
        if (ProtoClient.localPlayer == null && type == NetworkCharacterSyncerType.player)
        {
            ProtoClient.localPlayer = this;
            worldState.ModelData    = new ModelData();
            worldState.ModelData.PlayerAppearance = new PlayerAppearanceData();
        }
        var pc = GetComponent <PlayerCharacter>();

        if (pc != null && type == NetworkCharacterSyncerType.player)
        {
            pc.characterId = id;
        }
        worldState.IsPlayer = (type == NetworkCharacterSyncerType.player);
    }
Example #2
0
        public CharacterDomainBuilder HasState(CharacterWorldState state, byte value)
        {
            var condition = new HasWorldStateCondition(state, value);

            Pointer.AddCondition(condition);
            return(this);
        }
Example #3
0
 private static void AddNewCharacter(CharacterWorldState data)
 {
     if (!newSyncedCharactersLocked)
     {
         newSyncedCharacters.Add(data);
     }
 }
 public SetWorldStateEffect(CharacterWorldState state, bool value, EffectType type)
 {
     Name  = $"SetState({state})";
     Type  = type;
     State = state;
     Value = (byte)(value ? 1 : 0);
 }
 public SetWorldStateEffect(CharacterWorldState state, byte value, EffectType type)
 {
     Name  = $"SetState({state})";
     Type  = type;
     State = state;
     Value = value;
 }
 public IncrementWorldStateEffect(CharacterWorldState state, EffectType type)
 {
     Name  = $"IncrementState({state})";
     Type  = type;
     State = state;
     Value = 1;
 }
Example #7
0
 public CharacterDomainBuilder IncrementState(CharacterWorldState state, byte value, EffectType type)
 {
     if (Pointer is IPrimitiveTask task)
     {
         var effect = new IncrementWorldStateEffect(state, value, type);
         task.AddEffect(effect);
     }
     return(this);
 }
Example #8
0
 public static async void UpdatePersonalWorldState(CharacterWorldState worldState)
 {
     worldState.IsPlayer  = true;
     worldState.IsVisible = true;
     TimeSpan t         = (DateTime.UtcNow - new DateTime(1970, 1, 1));
     double   timestamp = t.TotalSeconds;
     var      request   = new CharacterWorldStateUpdate()
     {
         GameId = gameId, WorldState = worldState, UpdateTime = timestamp
     };
     var result = await characterSyncClient.UpdatePersonalWorldStateAsync(request);
 }
Example #9
0
 private static void FindOrUpdateWorldState(CharacterWorldState data, double oldTime, double newTime)
 {
     foreach (var syncer in syncedCharacters)
     {
         if (syncer.worldState.Id == data.Id)
         {
             syncer.worldState = data;
             return;
         }
     }
     AddNewCharacter(data);
 }
        public void SetState(CharacterWorldState state, byte value, EffectType type)
        {
            var oldValue = WorldState[(int)state];

            SetState((int)state, value, true, type);

            // We do some special handling here that we can support changing certain stats through planner effects.
            if (ContextState == ContextState.Executing && Self != null && oldValue != value)
            {
                switch (state)
                {
                case CharacterWorldState.Mana:
                    Self.Mana = value;
                    break;
                }
            }
        }
 public void SetState(CharacterWorldState state, int value, EffectType type)
 {
     SetState((int)state, (byte)value, true, type);
 }
 public void SetState(CharacterWorldState state, bool value, EffectType type)
 {
     SetState((int)state, (byte)(value ? 1 : 0), true, type);
 }
 public bool HasState(CharacterWorldState state)
 {
     return(HasState((int)state, 1));
 }
 public bool HasState(CharacterWorldState state, byte value)
 {
     return(HasState((int)state, value));
 }
 public bool HasState(CharacterWorldState state, bool value)
 {
     return(HasState((int)state, (byte)(value ? 1 : 0)));
 }
 private void AddNewCharacter(CharacterWorldState data)
 {
     foreach (var item in ProtoClient.syncedCharacters)
     {
         if (item.worldState.Id == data.Id)
         {
             return;
         }
     }
     if (data.IsPlayer)
     {
         var prefab     = Resources.Load("Prefabs/Player/kittenCharacter") as GameObject;
         var newPlayer  = Instantiate(prefab);
         var components = newPlayer.GetComponents(typeof(MonoBehaviour));
         foreach (MonoBehaviour component in components)
         {
             component.enabled = false;
         }
         //newPlayer.GetComponent<InputController>().enabled = true;
         newPlayer.GetComponent <CacheGrabber>().enabled = true;
         newPlayer.GetComponent <PlayerSyncer>().enabled = true;
         //newPlayer.GetComponent<PlayerSyncer>().furType = data.ModelData.PlayerAppearance.FurType;
         //newPlayer.GetComponent<PlayerSyncer>().furTypeSet = true;
         newPlayer.GetComponent <NetworkCharacterSyncer>().enabled    = true;
         newPlayer.GetComponent <NetworkCharacterSyncer>().worldState = data;
         newPlayer.GetComponent <Character>().enabled       = true;
         newPlayer.GetComponent <PlayerCharacter>().enabled = true;
     }
     else
     {
         var prefab     = Resources.Load("Prefabs/Monsters/" + data.ModelData.MonsterPrefab.PrefabName) as GameObject;
         var newMonster = Instantiate(prefab);
         var components = newMonster.GetComponents(typeof(MonoBehaviour));
         foreach (MonoBehaviour component in components)
         {
             component.enabled = false;
         }
         var mac = newMonster.GetComponent <MonsterAnimationController>();
         mac.enabled = true;
         if (data.AnimationState.State == "attacking")
         {
             mac.attacking = true;
         }
         else
         {
             mac.attacking = false;
         }
         if (data.AnimationState.State == "moving")
         {
             mac.moving = true;
         }
         else
         {
             mac.moving = false;
         }
         var animator  = newMonster.GetComponent <Animator>();
         var animation = newMonster.GetComponent <Animation>();
         if (animator != null)
         {
             animator.enabled = true;
         }
         if (animation != null)
         {
             animation.enabled = true;
         }
         newMonster.GetComponent <NetworkCharacterSyncer>().enabled    = true;
         newMonster.GetComponent <NetworkCharacterSyncer>().worldState = data;
     }
 }
 public HasWorldStateCondition(CharacterWorldState state, byte value)
 {
     Name  = $"HasState({state})";
     State = state;
     Value = value;
 }
 public byte GetState(CharacterWorldState state)
 {
     return(GetState((int)state));
 }