Example #1
0
 public override void Initialize()
 {
     serializeContext = delegate(bool pretty)
     {
         //TODO: create info field (optimization)
         CharacterData info = new CharacterData();
         info.Name             = Name;
         info.DataType         = typeof(CharacterData).ToString();
         info.ReferenceId      = ReferenceId;
         info.Position         = transform.position.Round(6);
         info.Rotation         = transform.rotation.eulerAngles.Round(3);
         info.Size             = transform.localScale;
         info.Groups           = Groups.ToArray();
         info.CurrentAnimation = CurrentAnimation;
         List <StatData> statsData = new List <StatData>();
         foreach (KeyValuePair <string, Stat> pair in stats)
         {
             StatData data = new StatData();
             data.Name  = pair.Key;
             data.Value = pair.Value.EffectiveValue;
             statsData.Add(data);
         }
         info.IsDead          = IsDead;
         info.LookingPos      = headLookingPos.Round(4);
         info.OwnerName       = Owner.Name;
         info.EquipedWeaponId = (EquipedWeapon != null) ? EquipedWeapon.Settings.Id : -1;
         return(JsonUtility.ToJson(info, pretty));
     };
     for (int i = 0; i < CharacterClass.SkillIds.Length; i++)
     {
         ScriptInfo     info  = ScriptDatabase.GetInstance().GetScript(CharacterClass.SkillIds[i]);
         SkillBehaviour skill = ScriptableObject.CreateInstance(info.Script.GetClass()) as SkillBehaviour;
         AddSkill(skill);
     }
 }
Example #2
0
 public void AddSkill(SkillBehaviour skill)
 {
     if (!skills.ContainsValue(skill))
     {
         skill.Caster = this;
         skill.Initialize();
         skills[skills.Count + 1] = skill;
     }
 }
Example #3
0
 public void DecodeJson(string json)
 {
     //TODO: Strategy Pattern
     try
     {
         PacketData jsonData = JsonUtility.FromJson <PacketData>(json);
         if (jsonData.DataType == typeof(CharacterData).ToString())
         {
             CharacterData charData = JsonUtility.FromJson <CharacterData>(json);
             otherPlayerLastData = charData;
             NetUpdate();
         }
         else
         {
             if (jsonData.DataType == typeof(ScriptableData).ToString())
             {
                 ScriptableData scriptData = JsonUtility.FromJson <ScriptableData>(json);
                 ScriptInfo     info       = ScriptDatabase.GetInstance().GetScript(scriptData.ScriptId);
                 SkillBehaviour skill      = ScriptableObject.CreateInstance(info.Script.GetClass()) as SkillBehaviour;
                 skill.Caster = otherPlayer;
                 skill.Initialize();
                 if (skill.OnCast != null)
                 {
                     Debug.Log("Cast");
                     skill.OnCast.RunContext();
                 }
             }
             else if (jsonData.DataType == typeof(ProjectileSpawnData).ToString())
             {
                 ProjectileSpawnData projData = JsonUtility.FromJson <ProjectileSpawnData>(json);
                 UnityMainThreadDispatcher.Instance().Enqueue(() =>
                 {
                     spawner.SpawnProjectile(projData.PrefabResourcePath, projData);
                 });
             }
             else
             {
                 SpawnData objSpawnData = JsonUtility.FromJson <SpawnData>(json);
                 UnityMainThreadDispatcher.Instance().Enqueue(() =>
                 {
                     spawner.SpawnObject(objSpawnData.PrefabResourcePath, objSpawnData);
                 });
             }
         }
     }
     catch
     {
         return;
     }
 }
Example #4
0
 protected virtual void Start()
 {
     ragdollColliders = GetComponentsInChildren <Collider>();
     foreach (Collider col in ragdollColliders)
     {
         if (col != GetComponent <Collider>())
         {
             col.isTrigger = true;
         }
     }
     if (modelRenderer != null)
     {
         modelRenderer.material.SetColor("_DissolveColor", DissolveColor);
     }
     for (int i = 0; i < SkillSet.Count; i++)
     {
         SkillBehaviour skill = ScriptableObject.CreateInstance(SkillSet[i].GetClass()) as SkillBehaviour;
         AddSkill(skill);
     }
 }
Example #5
0
        public virtual bool CastSkill(int id)
        {
            if (!skills.ContainsKey(id) || skillGlobalCooldown > 0)
            {
                return(false);
            }
            SkillBehaviour behaviour = skills[id];

            if (behaviour.CastCondition != null && !behaviour.CastCondition())
            {
                return(false);
            }
            skillGlobalCooldown = behaviour.Stats["Duration"].EffectiveValue;
            if (behaviour.OnPrepare != null)
            {
                behaviour.OnPrepare.RunContext();
            }
            else if (behaviour.OnCast != null)
            {
                behaviour.OnCast.RunContext();
            }
            behaviour.SendData();
            return(true);
        }