Ejemplo n.º 1
0
        public void HandleStatChanges(object entity, StatChangedEventArgs statChange)
        {
            var e = entity as Entity;

            if (e == null || e != this && statChange.UpdateSelfOnly)
            {
                return;
            }

            using (TimedLock.Lock(_statUpdateLock))
            {
                if (e == this && statChange.Stat == StatsType.None)
                {
                    return;
                }

                if (!_statUpdates.ContainsKey(e))
                {
                    _statUpdates[e] = new Dictionary <StatsType, object>();
                }

                if (statChange.Stat != StatsType.None)
                {
                    _statUpdates[e][statChange.Stat] = statChange.Value;
                }

                //Log.Info($"{entity} {statChange.Stat} {statChange.Value}");
            }
        }
 private void StatChanged(object sender, StatChangedEventArgs a)
 {
     if (OnStatChanged != null)
     {
         OnStatChanged(this, a);
     }
 }
 private void StatChanged(object sender, StatChangedEventArgs a)
 {
     if (OnStatChanged != null)
     {
         StatType type = Stats.First(s => s.Value.Equals(a.NewStat)).Key;
         OnStatChanged(this, new StatChangedEventArgs(ID, type, a.NewStat));
     }
 }
Ejemplo n.º 4
0
        private void ServerCharacter_HealthChanged(Character character, StatChangedEventArgs e) //private void ServerCharacter_HealthChanged(object sender, Character.HealthChangedEventArgs e)
        {
            if (e.Value != e.PreviousValue)                                                     //Why does not this get called?
            {
                ServerCharacter servCharacter = (ServerCharacter)character;
                this.SendStatChangeToMapCharacters(servCharacter);
                if (e.Value <= 0 && e.PreviousValue > 0)
                {
                    CorpseItem corpse = (CorpseItem)this.CreateNewItem(ItemIdentity.Corpse, character.CurrentMapId, servCharacter.Position, character.Id);
                    //corpse.CharacterID = character.Id;
                    //corpse.MoveTo(character.CurrentMapId, servCharacter.Position);
                    //CorpseItem corpse = new CorpseItem();
                    //corpse.Data = new ItemModel();
                    //corpse.Data.Identity = ItemIdentity.Corpse;
                    //corpse.Data = dataContext.SaveItem(corpse.Data);

                    if (corpse.Id != 0)
                    {
                        this.AddItem(corpse);
                        foreach (var item in servCharacter.Inventory.Items)
                        {
                            servCharacter.MoveItem(item, corpse);
                        }

                        foreach (int charID in this.maptoCharacterRelations[character.CurrentMapId])
                        {
                            ServerCharacter informChar = (ServerCharacter)this.GetCharacter(charID);
                            informChar.Owner.Send(new NewItemPacket(corpse.Id));
                            foreach (var item in corpse.Items)
                            {
                                informChar.Owner.Send(new MoveItemPacket(servCharacter.Inventory.Id, corpse.Id));
                            }
                        }

                        //servCharacter.MoveItem(servCharacter.Inventory, corpse); //                         item.Data.MoveTo(corpse.Data);
                        //dataContext.SaveItem(servCharacter.Inventory.Data);
                    }

                    //this.SendStatChangeToMapCharacters(servCharacter);
                }
                //else if (e.Value > 0 && e.PreviousValue <= 0)
                //{
                //    BagItem newInventory = new BagItem();
                //    newInventory.Data = new ItemData();
                //    newInventory.Data.Identity = ItemIdentity.Bag;
                //    newInventory.Data = dataContext.SaveItem(newInventory.Data);

                //    if (newInventory.Data.ItemDataID != 0)
                //    {
                //        this.AddItem(newInventory);
                //        servCharacter.Inventory = newInventory;
                //        servCharacter.LatestData.InventoryID = newInventory.Data.ItemDataID;
                //        dataContext.SaveCharacter(servCharacter.GetData());
                //    }
                //}
            }
        }
Ejemplo n.º 5
0
    public void Intelligence_Changed(GameObject sender, StatChangedEventArgs e)
    {
        var difference = e.newValue - e.oldValue;
        float currentPercentage = (float)CurrentValue / MaxValue;
        this.SetMaxValue(Mathf.Max(1, MaxValue + (difference * IntelligenceStat.manaPerIntel)));

        //Retain percentage on stat gain (dota-esque)
        this.SetCurrentValue((int)(this.MaxValue * currentPercentage));
    }
Ejemplo n.º 6
0
    public void Strength_Changed(GameObject sender, StatChangedEventArgs e)
    {
        var difference = e.newValue - e.oldValue;
        float currentPercentage = (float)CurrentValue / MaxValue;
        this.SetMaxValue(Mathf.Max(1, MaxValue + (difference * StrengthStat.healthPerStrength)));

        //Retain percentage on stat gain (dota-esque)
        this.SetCurrentValue((int)(this.MaxValue * currentPercentage));
    }
 private void ReflectDamage(Character character, StatChangedEventArgs e)
 {
     if (e.Value < e.PreviousValue && !this.IsUsed)
     {
         this.IsUsed = true;
         e.Value     = e.PreviousValue;
         character.Stats.Modifiers.Remove(this);
     }
 }
Ejemplo n.º 8
0
        private void Character_HealthChanged(Character character, StatChangedEventArgs e)
        {
            ClientCharacter clientCharacter = (ClientCharacter)character;

            if (e.Value <= e.PreviousValue) //Damage
            {
                this.AddDamageIndicator(clientCharacter, e.PreviousValue - e.Value);
                effectManager.AddEffect(new BloodEffect(clientCharacter.Position));
            }
            else //Healing
            {
                this.AddHealIndicator(clientCharacter, e.Value - e.PreviousValue);
            }
        }
        private void OnHealthChanged(Character character, StatChangedEventArgs e)
        {
            int damageToAbsorb  = 0;
            int maxAbsorbAmount = character.Stats.Energy;
            int damageAmount    = e.PreviousValue - e.Value;

            if (damageAmount < maxAbsorbAmount)
            {
                damageToAbsorb          = MathHelper.Clamp(damageAmount, byte.MinValue, byte.MaxValue);
                character.Stats.Energy -= damageToAbsorb;
                e.Value = e.PreviousValue;
            }

            damageToAbsorb          = MathHelper.Clamp(maxAbsorbAmount, byte.MinValue, byte.MaxValue);
            character.Stats.Energy -= damageToAbsorb;

            int returnHealth = MathHelper.Clamp(e.Value + damageToAbsorb, byte.MinValue, byte.MaxValue);

            e.Value = returnHealth;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Increases the stat of the player character. The increase will go with the Triangular
        /// number formula, n(n + 1) / 2, so to increase the stat from 0 to 5, you would need to
        /// input 15 into the function. Any remainding numbers will be stored into a buffer and
        /// included in the computation on the next time the stat is increased.
        /// </summary>
        /// <param name="stat">The stat to increase.</param>
        /// <param name="value">The factor in which to increase the stat.</param>
        public void IncreaseStat(Stat stat, uint value)
        {
            StatChangedEventArgs e;

            switch (stat)
            {
            case Stat.Strength:
                e = new StatChangedEventArgs(Stat.HealthMax, this.HealthMax);

                this.IncreaseStat(
                    ref this.strength,
                    Stat.Strength,
                    value,
                    () => this.StatChanged?.Invoke(this, e));
                break;

            case Stat.Intelligence:
                e = new StatChangedEventArgs(Stat.ManaMax, this.ManaMax);

                this.IncreaseStat(
                    ref this.intelligence,
                    Stat.Intelligence,
                    value,
                    () => this.StatChanged?.Invoke(this, e));
                break;

            case Stat.Agility:
                e = new StatChangedEventArgs(Stat.StaminaMax, this.StaminaMax);

                this.IncreaseStat(
                    ref this.agility,
                    Stat.Agility,
                    value,
                    () => this.StatChanged?.Invoke(this, e));
                break;

            case Stat.Vitality:
                StatChangedEventArgs e1 = new StatChangedEventArgs(Stat.HealthMax, this.HealthMax);
                StatChangedEventArgs e2 = new StatChangedEventArgs(Stat.StaminaMax, this.StaminaMax);

                this.IncreaseStat(
                    ref this.vitality,
                    Stat.Vitality,
                    value,
                    () =>
                {
                    StatChanged?.Invoke(this, e1);
                    StatChanged?.Invoke(this, e2);
                });
                break;

            case Stat.Luck:
                this.IncreaseStat(ref this.luck, Stat.Luck, value, null);
                break;

            case Stat.WeaponUse:
                this.IncreaseStat(ref this.weaponUse, Stat.WeaponUse, value, null);
                break;

            case Stat.Parry:
                this.IncreaseStat(ref this.parry, Stat.Parry, value, null);
                break;

            case Stat.Dodge:
                this.IncreaseStat(ref this.dodge, Stat.Dodge, value, null);
                break;

            case Stat.Stealth:
                this.IncreaseStat(ref this.stealth, Stat.Stealth, value, null);
                break;

            case Stat.LockPicking:
                this.IncreaseStat(ref this.lockPicking, Stat.LockPicking, value, null);
                break;

            case Stat.Throwing:
                this.IncreaseStat(ref this.throwing, Stat.Throwing, value, null);
                break;

            case Stat.Climbing:
                this.IncreaseStat(ref this.climbing, Stat.Climbing, value, null);
                break;

            case Stat.Magic:
                e = new StatChangedEventArgs(Stat.ManaMax, this.ManaMax);

                this.IncreaseStat(
                    ref this.magic,
                    Stat.Magic,
                    value,
                    () => this.StatChanged?.Invoke(this, e));
                break;

            case Stat.Health:
            case Stat.HealthMax:
            case Stat.Stamina:
            case Stat.StaminaMax:
            case Stat.Mana:
            case Stat.ManaMax:
            case Stat.Humans:
            case Stat.Sidhe:
            case Stat.Giants:
                throw new NotImplementedException(
                          $"Enum {stat} is not intended to be set here, use property instead.");

            default:
                throw new InvalidEnumArgumentException(nameof(stat), (int)stat, typeof(Stat));
            }
        }
Ejemplo n.º 11
0
 protected void OnChanged(GameObject sender, StatChangedEventArgs e)
 {
     if (Changed != null)
         Changed(sender, e);
 }
Ejemplo n.º 12
0
    //public Item EquipItem(Item item)
    //{
    //    EquipSlotType slot = item.SlotType;

    //    if (equipment.ContainsKey(slot))
    //    {
    //        Item unequippedItem = equipment[slot];
    //        equipment.Remove(slot);
    //        equipment.Add(slot, item);

    //        return unequippedItem;
    //    }

    //    equipment.Add(slot, item);
    //    return null;
    //}

    //public Item UnEquipItem(EquipSlotType type)
    //{
    //    if (equipment.ContainsKey(type) == true)
    //    {
    //        Item item = equipment[type];
    //        equipment.Remove(type);
    //        return item;
    //    }

    //    return null;
    //}

    private void CharacterSheet_OnStatChanged(object sender, StatChangedEventArgs args)
    {
        updateBaseModifier(args.stat.statType);
    }