Example #1
0
 private void MagicSkillLearned(IMagicUser sender, int skillId)
 {
     if (skillId > -1)
     {
         BaseSkill skill = SkillDatabase.GetMagicSkillById(skillId);
         AddSkillPanel(skill);
     }
 }
Example #2
0
        /// <summary>
        /// Trigger the given magic skill.</summary>
        /// <param name="skillId">The id of the magic skill.</param>
        /// <returns>Whether the magic skill was triggered.</returns>
        public bool TriggerMagicSkill(int skillId)
        {
            if (!MagicSkillCanBeUsed(skillId))
            {
                return(false);
            }
            var magicSkill = SkillDatabase.GetMagicSkillById(skillId);

            Magic -= magicSkill.Cost;
            MagicSkillEndTimes[MagicSkills.IndexOf(skillId)] = GameTime.time + magicSkill.CooldownTime;
            EmitOnMagicSkillTriggered(skillId);
            return(true);
        }
Example #3
0
        /// <summary>
        /// Check if the character knows the magic skill, has enough
        /// magic energy and is not in cooldown of the Skill.</summary>
        /// <param name=magicSkill>The Skill to test</param>
        /// <returns> Whether the Skill van be used.</returns>
        private bool MagicSkillCanBeUsed(int skillId)
        {
            if (GameTime.time < TimeUntilNextAttack)
            {
                return(false);
            }
            if (!MagicSkills.Contains(skillId))
            {
                return(false);
            }
            var magicSkill = SkillDatabase.GetMagicSkillById(skillId);

            if (Magic < magicSkill.Cost)
            {
                return(false);
            }
            return(GameTime.time >= MagicSkillEndTimes[MagicSkills.IndexOf(skillId)]);
        }
Example #4
0
 /// <summary>
 /// Display the magic and combat skills.</summary>
 /// <param name="character"></param>
 void DrawSkills(BaseCharacter character)
 {
     EditorGUILayout.LabelField("Magic Skills", GUILayout.Width(200));
     foreach (var skill in character.MagicSkills)
     {
         EditorGUILayout.BeginHorizontal("box");
         EditorGUILayout.LabelField(SkillDatabase.GetMagicSkillById(skill).Name, GUILayout.Width(200));
         if (GUILayout.Button("X", GUILayout.Width(25)))
         {
             character.MagicSkills.Remove(skill);
             character.MagicSkillEndTimes = new List <float>();
             foreach (int s in character.MagicSkills)
             {
                 character.MagicSkillEndTimes.Add(-1);
             }
             EditorUtility.SetDirty(target);
             EditorGUILayout.EndHorizontal();
             break;
         }
         EditorGUILayout.EndHorizontal();
     }
     EditorGUILayout.LabelField("Combat Skills", GUILayout.Width(200));
     foreach (var skill in character.CombatSkills)
     {
         EditorGUILayout.BeginHorizontal("box");
         EditorGUILayout.LabelField(SkillDatabase.GetCombatSkillById(skill).Name, GUILayout.Width(200));
         if (GUILayout.Button("X", GUILayout.Width(25)))
         {
             character.CombatSkills.Remove(skill);
             character.CombatSkillEndTimes = new List <float>();
             foreach (int c in character.CombatSkills)
             {
                 character.CombatSkillEndTimes.Add(-1);
             }
             EditorUtility.SetDirty(target);
             EditorGUILayout.EndHorizontal();
             break;
         }
         EditorGUILayout.EndHorizontal();
     }
 }
Example #5
0
        /// <summary>
        /// Triggers the use of the Skill</summary>
        /// <param name=skillId>The Skill to use</param>
        public void UseMagicSkill(int skillId)
        {
            var magicSkill = SkillDatabase.GetMagicSkillById(skillId);

            magicSkill.Use(this);
        }
Example #6
0
    public void Initialize()
    {
        Player = (Player)GamePlayer.Instance.Character;

        // Connect the Signals from the Player
        Player.Stats.Life.OnValueChanged  += new ValueChangedHandler(UpdateLifeSlider);
        Player.Stats.Magic.OnValueChanged += new ValueChangedHandler(UpdateMagicSlider);
        Player.OnCombatSkillUsed          += new CombatSkillUsedHandler(UpdateEnemyLifeSlider);
        Player.OnStateChanged             += new StateChangedHandler(ToggleEnemyPanel);
        Player.Stats.Body.OnValueChanged  += new ValueChangedHandler(UpdateStats);
        Player.Stats.Mind.OnValueChanged  += new ValueChangedHandler(UpdateStats);
        Player.Stats.Soul.OnValueChanged  += new ValueChangedHandler(UpdateStats);
        Player.OnWeaponEquipped           += new WeaponEquippedHandler(UpdateWeaponStats);
        Player.Stats.Level.OnValueChanged += new ValueChangedHandler(NextLevelReached);
        Player.OnMagicSkillLearned        += new MagicSkillLearnedHandler(MagicSkillLearned);
        Player.Inventory.OnItemAdded      += new ItemAddedHandler(FoundItem);

        // Set the initial values
        UpdateLifeSlider(Player.Stats.Life, Player.Stats.Life.Value);
        UpdateMagicSlider(Player.Stats.Magic, Player.Stats.Magic.Value);
        UpdateStats(Player.Stats.Body, Player.Stats.Body.Value);
        AvailableAttributePointsText.text = Player.AvailableAttributePoints.ToString();

        // The Inventory and the equipped Weapon
        InventoryView.Initialize();
        foreach (KeyValuePair <int, SlottableItem> entry in InventoryView._items)
        {
            if (entry.Value.Item is WeaponItemData)
            {
                var weaponItemData = entry.Value.Item as WeaponItemData;
                if (weaponItemData.Item.Id == Player.EquippedWeapon)
                {
                    ActionPanel.WeaponSlot.Swap(entry.Value);
                    break;
                }
            }
        }

        // The equipped items
        for (int i = 0; i < Player.EquippedItems.Length; i++)
        {
            foreach (KeyValuePair <int, SlottableItem> entry in InventoryView._items)
            {
                if (entry.Value.Item is UsableItemData)
                {
                    var usableItemData = entry.Value.Item as UsableItemData;
                    if (usableItemData.Item.Id == Player.EquippedItems[i])
                    {
                        ActionPanel.Slots[i].Swap(entry.Value);
                        break;
                    }
                }
            }
        }

        // The Skill Panels
        foreach (int skillId in Player.MagicSkills)
        {
            if (skillId > -1)
            {
                BaseSkill skill = SkillDatabase.GetMagicSkillById(skillId);
                AddSkillPanel(skill);
            }
        }

        // The Quest Panel
        foreach (UQuest quest in UStoryline.Instance.Quests)
        {
            var panel = Instantiate <QuestPanel>(QuestPanelPrefab);
            panel.Initialize(quest);
            panel.transform.SetParent(QuestPanel.transform);
            panel.transform.localScale = new Vector3(1, 1, 1);
            panel.GetComponent <RectTransform>().anchoredPosition3D = new Vector3(0, 0, 0);
            QuestPanels.Add(panel);
        }

        // Reset the UI
        EnemyPanel.SetActive(false);
        InfoText.enabled = false;
        DisableSaving();
    }