private EquipmentWrapper CreateNewEquipment() //calls the add method in the repository to insert new equipment and return it
        {
            var equipment = new EquipmentWrapper(new Model.Equipment());

            //when property in equipment changes, and it has errors, disable the create button
            equipment.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(Equipment.HasErrors))
                {
                    ((DelegateCommand)CreateEquipmentCommand).RaiseCanExecuteChanged();
                }
            };
            ((DelegateCommand)CreateEquipmentCommand).RaiseCanExecuteChanged();

            //default values
            equipment.EquipmentSerialnumber    = "";
            equipment.EquipmentStatus          = false;
            equipment.EquipmentDateCreated     = DateTime.Now;
            equipment.EquipmentCategoryId      = 1;
            equipment.EquipmentConfigurationID = 1;
            equipment.EquipmentTypeID          = 1;

            _equipmentRepository.Add(equipment.Model); //context is aware of the equipment to add
            return(equipment);
        }
Esempio n. 2
0
    IEnumerator AIvsAI(CharacterWrapper playerOne, CharacterWrapper playerTwo)
    {
        while (true)
        {
            yield return(null);

            Equipment.Ability oneAction;
            EquipmentWrapper  oneEquip = playerOne.GetAbility(out oneAction);
            Equipment.Ability twoAction;
            EquipmentWrapper  twoEquip = playerTwo.GetAbility(out twoAction);
            HandleAction(playerOne, playerTwo, ref oneAction, ref twoAction);
            HandleAction(playerTwo, playerOne, ref twoAction, ref oneAction);
            if (oneEquip != null)
            {
                playerOne.RemoveEquipment(oneEquip);
            }
            if (twoEquip != null)
            {
                playerTwo.RemoveEquipment(twoEquip);
            }
            if (playerOne.health <= 0 && playerTwo.health >= playerOne.health)
            {
                GameState.State.DefeatCharacter(playerOne);
                yield break;
            }
            else if (playerTwo.health <= 0 && playerOne.health > playerTwo.health)
            {
                GameState.State.DefeatCharacter(playerTwo);
                yield break;
            }
            playerOne.NextTurn();
            playerTwo.NextTurn();
        }
    }
        private void OnAddExecute()
        {
            var wrapper = new EquipmentWrapper(new Equipment());

            wrapper.PropertyChanged += Wrapper_PropertyChanged;
            _equipmentRepository.Add(wrapper.Model);
            Equipments.Add(wrapper);

            //trigger the validation
            wrapper.Name = "";
        }
Esempio n. 4
0
    public void SetCards(CharacterWrapper character, Action <EquipmentWrapper, Equipment.Ability> onSelect)
    {
        bool hasAction = false;
        List <EquipmentWrapper> list = character.equipment;
        bool hasInventory            = character.inventory.Count > 0;

        while (transform.childCount < list.Count + 2)
        {
            Instantiate(transform.GetChild(0).gameObject, transform);
        }
        for (int i = 0; i < list.Count; i++)
        {
            EquipmentWrapper e = list[i];
            Transform        t = transform.GetChild(i);
            t.GetChild(0).GetComponent <Image>().sprite = e.equipment.icon;
            t.GetChild(1).GetComponent <Text>().text    = e.ActionString();
            Button b = t.GetComponent <Button>();
            b.onClick.RemoveAllListeners();
            b.onClick.AddListener(() => { onSelect(e, null); });
            b.interactable = e.cooldown <= 0;
            hasAction      = hasAction | b.interactable;
            t.gameObject.SetActive(true);
        }
        for (int i = list.Count; i < transform.childCount; i++)
        {
            transform.GetChild(i).gameObject.SetActive(false);
        }
        if (hasInventory)
        {
            Transform t = transform.GetChild(list.Count);
            t.GetChild(0).GetComponent <Image>().sprite = changeIcon;
            Button b = t.GetComponent <Button>();
            b.onClick.RemoveAllListeners();
            t.GetChild(1).GetComponent <Text>().text = "Swap Equipment";
            b.onClick.AddListener(() => { onSelect(null, null); });
            b.interactable = true;
            t.gameObject.SetActive(true);
        }
        if (!hasAction)
        {
            Transform t = transform.GetChild(list.Count + 1);
            t.GetChild(0).GetComponent <Image>().sprite = changeIcon;
            Button b = t.GetComponent <Button>();
            b.onClick.RemoveAllListeners();
            Equipment.Ability playerAction = new Equipment.Ability();
            playerAction.action = Equipment.Action.none;
            playerAction.name   = "Wait";
            t.GetChild(1).GetComponent <Text>().text = "Wait";
            b.onClick.AddListener(() => { onSelect(null, playerAction); });
            b.interactable = true;
            t.gameObject.SetActive(true);
        }
    }
Esempio n. 5
0
 public void AddInventory(EquipmentWrapper e)
 {
     inventory.Add(e);
     strength--;
     agility--;
     constitution--;
     intelligence--;
     if (this == GameState.State.player)
     {
         FlashText.Flash("All Stats: -1", Color.red);
     }
 }
Esempio n. 6
0
 public static void OpenExpensiveSmall()
 {
     instance.content = new List <EquipmentWrapper>();
     instance.num     = 1;
     for (int i = 0; i < 3; i++)
     {
         var e = new EquipmentWrapper(instance.expensiveLoot[Random.Range(0, instance.expensiveLoot.Length)]);
         e.durability = (Random.Range(1, e.durability - 1) + Random.Range(1, e.durability - 1)) / 2;
         instance.content.Add(e);
     }
     instance.Refresh();
     AudioPlayer.PlayPling();
 }
Esempio n. 7
0
 public void ThrowEquipment(EquipmentWrapper ew)
 {
     if (!battleUI.activeSelf)
     {
         return;
     }
     Inventory.Close();
     Equipment.Ability ac = new Equipment.Ability();
     ac.action = Equipment.Action.damage;
     ac.amount = ew.equipment.type == Equipment.Type.weapon ? 6 : 4;
     ac.name   = "Throw " + ew.equipment.name;
     SetPlayerAction(ew, ac);
     reward += 20;
 }
Esempio n. 8
0
 public void RemoveInventory(EquipmentWrapper e)
 {
     if (inventory.Remove(e))
     {
         strength++;
         agility++;
         constitution++;
         intelligence++;
         if (this == GameState.State.player)
         {
             FlashText.Flash("All Stats: +1", Color.green);
         }
     }
 }
Esempio n. 9
0
 void SetPlayerAction(EquipmentWrapper e, Equipment.Ability action)
 {
     if (e == null && action == null)
     {
         Inventory.Show(player);
     }
     else
     {
         playerCards.Clear();
         Equipment.Ability playerAction;
         bool remove = false;
         if (action != null)
         {
             playerAction = action;
         }
         else
         {
             remove = !e.NextAction(out playerAction);
         }
         Equipment.Ability enemyAction;
         var ee = enemy.GetAbility(out enemyAction);
         FlashText.Flash(enemyAction.name + "\n\n\n\n" + playerAction.name, Color.white);
         HandleAction(player, enemy, ref playerAction, ref enemyAction, playerAnimation, enemyAnimation);
         HandleAction(enemy, player, ref enemyAction, ref playerAction, enemyAnimation, playerAnimation);
         if (remove)
         {
             FlashText.Flash("Your " + e.equipment.name.ToLower() + " broke!", Color.red);
             player.RemoveEquipment(e);
         }
         if (ee != null)
         {
             enemy.RemoveEquipment(ee);
         }
         if (player.health <= 0 && enemy.health >= player.health)
         {
             StartCoroutine(BattleOver(player));
             return;
         }
         else if (enemy.health <= 0 && player.health > enemy.health)
         {
             StartCoroutine(BattleOver(enemy));
             return;
         }
         reward += 3;
         StartCoroutine(DelayedNextTurn());
     }
 }
        public async override Task LoadAsync(int id)
        {
            Id = id;
            foreach (var wrapper in Equipments)
            {
                wrapper.PropertyChanged -= Wrapper_PropertyChanged;
            }

            Equipments.Clear();
            var equipments = await _equipmentRepository.GetAllAsync();

            foreach (var model in equipments)
            {
                var wrapper = new EquipmentWrapper(model);
                wrapper.PropertyChanged += Wrapper_PropertyChanged;
                Equipments.Add(wrapper);
            }
        }
        private async void OnRemoveExecute()
        {
            var isReferenced = await _equipmentRepository.IsReferencedByExerciseAsync(SelectedEquipment.Id);

            if (isReferenced)
            {
                await MessageDialogService.ShowInfoDialogAsync($"{SelectedEquipment.Name} не може да бъде премахнато" +
                                                               $", понеже се съдържа в поне едно упражнение.");

                return;
            }

            SelectedEquipment.PropertyChanged -= Wrapper_PropertyChanged;
            _equipmentRepository.Remove(SelectedEquipment.Model);
            Equipments.Remove(SelectedEquipment);
            SelectedEquipment = null;
            HasChanges        = _equipmentRepository.HasChanges();
            ((DelegateCommand)SaveCommand).RaiseCanExecuteChanged();
        }
Esempio n. 12
0
    public void RemoveEquipment(EquipmentWrapper e)
    {
        if (equipment.Remove(e))
        {
            strength     -= e.equipment.strength;
            agility      -= e.equipment.agility;
            constitution -= e.equipment.constitution;
            intelligence -= e.equipment.intelligence;

            if (e.durability > 0 && this == GameState.State.player)
            {
                SwapPopup.Popup(e.ToString(), (b) => {
                    if (b)
                    {
                        AddInventory(e);
                    }
                    else
                    {
                        GameState.State.battleManager.ThrowEquipment(e);
                    }
                });
            }

            if (e.equipment.type == Equipment.Type.weapon && character.baseWeapon != null)
            {
                bool hasWeapon = false;
                for (int i = 0; i < equipment.Count; i++)
                {
                    if (equipment[i].equipment.type == Equipment.Type.weapon)
                    {
                        hasWeapon = true;
                        break;
                    }
                }
                if (!hasWeapon)
                {
                    AddEquipment(character.baseWeapon);
                }
            }
        }
    }
Esempio n. 13
0
 public void AddEquipment(EquipmentWrapper e)
 {
     equipment.Add(e);
     e.NextMatch();
     strength     += e.equipment.strength;
     agility      += e.equipment.agility;
     constitution += e.equipment.constitution;
     intelligence += e.equipment.intelligence;
     if (e.equipment.slot == Equipment.Slots.oneHand)
     {
         EquipmentWrapper old = null;
         for (int i = 0; i < equipment.Count - 1; i++)
         {
             if (equipment[i].equipment.slot == Equipment.Slots.bothHands)
             {
                 RemoveEquipment(equipment[i]);
                 break;
             }
             else if (equipment[i].equipment.slot == Equipment.Slots.oneHand)
             {
                 if (old == null)
                 {
                     old = equipment[i];
                 }
                 else
                 {
                     RemoveEquipment(old);
                     break;
                 }
             }
         }
     }
     else if (e.equipment.slot == Equipment.Slots.bothHands)
     {
         bool hasRemoved = false;
         for (int i = 0; i < equipment.Count - 1; i++)
         {
             if (equipment[i].equipment.slot == Equipment.Slots.bothHands || equipment[i].equipment.slot == Equipment.Slots.oneHand)
             {
                 if (hasRemoved)
                 {
                     if (this == GameState.State.player)
                     {
                         AddInventory(equipment[i]);
                     }
                     RemoveEquipment(equipment[i]);
                     i--;
                 }
                 else
                 {
                     RemoveEquipment(equipment[i]);
                     i--;
                     hasRemoved = true;
                 }
             }
         }
     }
     else
     {
         for (int i = 0; i < equipment.Count - 1; i++)
         {
             if (equipment[i].equipment.slot == e.equipment.slot)
             {
                 RemoveEquipment(equipment[i]);
                 break;
             }
         }
     }
     if (this == GameState.State.player)
     {
         GameState.State.battleManager.RefreshStatus();
     }
 }
Esempio n. 14
0
    public EquipmentWrapper GetAbility(out Equipment.Ability ability)
    {
        float sum = character.aggressive + character.defensive + character.utility;

        if (sum < 0.01f)
        {
            ability        = new Equipment.Ability();
            ability.name   = "Wait";
            ability.action = Equipment.Action.none;
            return(null);
        }
        float            rnd = Random.value * sum;
        EquipmentWrapper e   = null;

        if (rnd < character.aggressive)
        {
            for (int i = 0; i < equipment.Count; i++)
            {
                if ((equipment[i].equipment.type == Equipment.Type.aggressive || equipment[i].equipment.type == Equipment.Type.weapon) && equipment[i].cooldown <= 0)
                {
                    e = equipment[i];
                    int r = Random.Range(0, equipment.Count);
                    equipment[i] = equipment[r];
                    equipment[r] = e;
                    break;
                }
            }
            if (e == null)
            {
                float tmp = character.aggressive;
                character.aggressive = 0f;
                e = GetAbility(out ability);
                character.aggressive = tmp;
                return(e);
            }
        }
        else
        {
            rnd -= character.aggressive;
            if (rnd < character.defensive)
            {
                for (int i = 0; i < equipment.Count; i++)
                {
                    if ((equipment[i].equipment.type == Equipment.Type.armor || equipment[i].equipment.type == Equipment.Type.shield) && equipment[i].cooldown <= 0)
                    {
                        e = equipment[i];
                        int r = Random.Range(0, equipment.Count);
                        equipment[i] = equipment[r];
                        equipment[r] = e;
                        break;
                    }
                }
                if (e == null)
                {
                    float tmp = character.defensive;
                    character.defensive = 0f;
                    e = GetAbility(out ability);
                    character.defensive = tmp;
                    return(e);
                }
            }
            else
            {
                for (int i = 0; i < equipment.Count; i++)
                {
                    if (equipment[i].equipment.type == Equipment.Type.utility && equipment[i].cooldown <= 0)
                    {
                        e = equipment[i];
                        int r = Random.Range(0, equipment.Count);
                        equipment[i] = equipment[r];
                        equipment[r] = e;
                        break;
                    }
                }
                if (e == null)
                {
                    float tmp = character.utility;
                    character.utility = 0f;
                    e = GetAbility(out ability);
                    character.utility = tmp;
                    return(e);
                }
            }
        }
        if (!e.NextAction(out ability))
        {
            return(e);
        }
        return(null);
    }