Ejemplo n.º 1
0
        public static void showaffect(CharacterInstance ch, AffectData paf)
        {
            Validation.IsNotNull(paf, "paf");

            var buf = string.Empty;

            if (paf.Location == ApplyTypes.None || paf.Modifier == 0)
            {
                return;
            }

            switch (paf.Location)
            {
            default:
                buf = $"Affects {affect_loc_name((int)paf.Location)} by {paf.Modifier}.";
                break;

            case ApplyTypes.Affect:
                buf = $"Affects {affect_loc_name((int)paf.Location)} by {paf.Modifier}.";

                for (var i = 0; i < 32; i++)
                {
                    if (paf.Modifier.IsSet(1 << i))
                    {
                        buf += " " + BuilderConstants.a_flags[i];
                    }
                }
                break;

            case ApplyTypes.WeaponSpell:
            case ApplyTypes.WearSpell:
            case ApplyTypes.RemoveSpell:
                var name = "unknown";
                if (Macros.IS_VALID_SN(paf.Modifier))
                {
                    var skill = RepositoryManager.Instance.SKILLS.Get(paf.Modifier);
                    name = skill.Name;
                }
                buf = $"Casts spell '{name}'";
                break;

            case ApplyTypes.Resistance:
            case ApplyTypes.Immunity:
            case ApplyTypes.Susceptibility:
                buf = $"Affects {affect_loc_name((int)paf.Location)} by {paf.Modifier}";

                for (var i = 0; i < 32; i++)
                {
                    if (paf.Modifier.IsSet(1 << i))
                    {
                        buf += " " + BuilderConstants.ris_flags[i];
                    }
                }

                break;
            }

            ch.SendTo(buf);
        }
Ejemplo n.º 2
0
        private static int ModifyAndAddAffect(CharacterInstance ch, AffectData affect, int mod)
        {
            ch.AffectedBy.SetBit((int)affect.Type);
            if ((int)affect.Location % Program.REVERSE_APPLY == (int)ApplyTypes.RecurringSpell)
            {
                mod = Math.Abs(mod);
                var skill = RepositoryManager.Instance.SKILLS.Values.ToList()[mod];

                if (Macros.IS_VALID_SN(mod) && skill != null && skill.Type == SkillTypes.Spell)
                {
                    ch.AffectedBy.SetBit((int)AffectedByTypes.RecurringSpell);
                }
                else
                {
                    throw new InvalidDataException($"RecurringSpell with bad SN {mod}");
                }
            }
            return(mod);
        }
Ejemplo n.º 3
0
        public static void char_update()
        {
            //lc = trworld_create(TR_CHAR_WORLD_BACK)

            foreach (var ch in RepositoryManager.Instance.CHARACTERS.Values)
            {
                handler.CurrentCharacter = ch;

                if (!ch.IsNpc())
                {
                    MudProgHandler.ExecuteRoomProg(MudProgTypes.Random, ch);
                }
                if (ch.CharDied())
                {
                    continue;
                }

                if (ch.IsNpc())
                {
                    MudProgHandler.ExecuteMobileProg(MudProgTypes.Time, ch);
                }
                if (ch.CharDied())
                {
                    continue;
                }

                MudProgHandler.ExecuteRoomProg(MudProgTypes.Time, ch);
                if (ch.CharDied())
                {
                    continue;
                }

                CharacterInstance ch_save = null;
                if (!ch.IsNpc() && (((PlayerInstance)ch).Descriptor == null || ((PlayerInstance)ch).Descriptor.ConnectionStatus == ConnectionTypes.Playing) &&
                    ch.Level >= 2 && CheckSaveFrequency(ch))
                {
                    ch_save = ch;
                }

                if ((int)ch.CurrentPosition >= (int)PositionTypes.Stunned)
                {
                    if (ch.CurrentHealth < ch.MaximumHealth)
                    {
                        ch.CurrentHealth += ch.HealthGain();
                    }
                    if (ch.CurrentMana < ch.MaximumMana)
                    {
                        ch.CurrentMana += ch.ManaGain();
                    }
                    if (ch.CurrentMovement < ch.MaximumMovement)
                    {
                        ch.CurrentMovement += ch.MovementGain();
                    }
                }

                if (ch.CurrentPosition == PositionTypes.Stunned)
                {
                    ch.UpdatePositionByCurrentHealth();
                }

                // TODO Variables

                if (ch.CurrentMorph?.timer > 0)
                {
                    --ch.CurrentMorph.timer;
                    if (ch.CurrentMorph.timer == 0)
                    {
                        UnmorphChar.do_unmorph_char(ch, string.Empty);
                    }
                }

                // TODO Nuisance

                if (!ch.IsNpc() && ch.Level < LevelConstants.ImmortalLevel)
                {
                    var obj = ch.GetEquippedItem(WearLocations.Light);
                    if (obj != null && obj.ItemType == ItemTypes.Light && obj.Value.ToList()[2] > 0)
                    {
                        ProcessLightObject(ch, obj);
                    }

                    if (++ch.Timer >= 12)
                    {
                        ProcessIdle(ch);
                    }

                    if (((PlayerInstance)ch).PlayerData.GetConditionValue(ConditionTypes.Drunk) > 8)
                    {
                        ((PlayerInstance)ch).WorsenMentalState(((PlayerInstance)ch).PlayerData.GetConditionValue(ConditionTypes.Drunk) / 8);
                    }

                    if (((PlayerInstance)ch).PlayerData.GetConditionValue(ConditionTypes.Full) > 1)
                    {
                        // todo fix this
                        //IEnumerable<MentalStateAttribute> attribs =
                        //    ch.CurrentPosition.GetAttributes<MentalStateAttribute>();
                        //if (attribs.Any())
                        //{
                        //    MentalStateAttribute attrib =
                        //        attribs.FirstOrDefault(x => x.Condition.HasFlag(ConditionTypes.Full));
                        //    ch.ImproveMentalState(attrib == null ? 1 : attrib.ModValue);
                        //}
                    }

                    if (((PlayerInstance)ch).PlayerData.GetConditionValue(ConditionTypes.Thirsty) > 1)
                    {
                        // todo fix this
                        //IEnumerable<MentalStateAttribute> attribs =
                        //    ch.CurrentPosition.GetAttributes<MentalStateAttribute>();
                        //if (attribs.Any())
                        //{
                        //    MentalStateAttribute attrib =
                        //        attribs.FirstOrDefault(x => x.Condition.HasFlag(ConditionTypes.Thirsty));
                        //    ch.ImproveMentalState(attrib == null ? 1 : attrib.ModValue);
                        //}
                    }

                    ch.CheckAlignment();
                    ((PlayerInstance)ch).GainCondition(ConditionTypes.Drunk, -1);

                    var race = RepositoryManager.Instance.GetRace(ch.CurrentRace);
                    ((PlayerInstance)ch).GainCondition(ConditionTypes.Full, -1 + race.HungerMod);

                    if (ch.IsVampire() && ch.Level >= 10)
                    {
                        if (GameManager.Instance.GameTime.Hour < 21 && GameManager.Instance.GameTime.Hour >= 10)
                        {
                            ((PlayerInstance)ch).GainCondition(ConditionTypes.Bloodthirsty, -1);
                        }
                    }

                    if (ch.CanPKill() && ((PlayerInstance)ch).PlayerData.GetConditionValue(ConditionTypes.Thirsty) - 9 > 10)
                    {
                        ((PlayerInstance)ch).GainCondition(ConditionTypes.Thirsty, -9);
                    }

                    // TODO Nuisance
                }

                if (!ch.IsNpc() && !ch.IsImmortal() && ((PlayerInstance)ch).PlayerData.release_date > DateTime.MinValue &&
                    ((PlayerInstance)ch).PlayerData.release_date <= DateTime.Now)
                {
                    var location =
                        RepositoryManager.Instance.ROOMS.Get(((PlayerInstance)ch).PlayerData.Clan?.RecallRoom ??
                                                             VnumConstants.ROOM_VNUM_TEMPLE) ?? ch.CurrentRoom;

                    ch.CurrentRoom.RemoveFrom(ch);
                    location.AddTo(ch);
                    ch.SendTo("The gods have released you from hell as your sentence is up!");
                    Look.do_look(ch, "auto");
                    ((PlayerInstance)ch).PlayerData.helled_by    = string.Empty;
                    ((PlayerInstance)ch).PlayerData.release_date = DateTime.MinValue;
                    save.save_char_obj(ch);
                }

                if (!ch.CharDied())
                {
                    if (ch.IsAffected(AffectedByTypes.Poison))
                    {
                        comm.act(ATTypes.AT_POISON, "$n shivers and suffers.", ch, null, null, ToTypes.Room);
                        comm.act(ATTypes.AT_POISON, "You shiver and suffer.", ch, null, null, ToTypes.Character);

                        var minMentalState = CalculateMinMentalStateWhilePoisoned(ch);
                        ch.MentalState = 20.GetNumberThatIsBetween(minMentalState, 100);
                        ch.CauseDamageTo(ch, 6, RepositoryManager.Instance.LookupSkill("poison"));
                    }
                    else
                    {
                        switch (ch.CurrentPosition)
                        {
                        case PositionTypes.Incapacitated:
                            ch.CauseDamageTo(ch, 1, Program.TYPE_UNDEFINED);
                            break;

                        case PositionTypes.Mortal:
                            ch.CauseDamageTo(ch, 4, Program.TYPE_UNDEFINED);
                            break;
                        }
                    }
                    if (ch.CharDied())
                    {
                        continue;
                    }

                    if (ch.IsAffected(AffectedByTypes.RecurringSpell))
                    {
                        var died  = false;
                        var found = false;
                        foreach (var paf in ch.Affects.Where(x => x.Location == ApplyTypes.RecurringSpell))
                        {
                            found = true;
                            if (Macros.IS_VALID_SN(paf.Modifier))
                            {
                                var skill = RepositoryManager.Instance.SKILLS.Get(paf.Modifier);
                                if (skill == null || skill.Type != SkillTypes.Spell)
                                {
                                    continue;
                                }

                                var retCode = skill.SpellFunction.Value.Invoke(paf.Modifier, ch.Level, ch, ch);
                                if (retCode == ReturnTypes.CharacterDied || ch.CharDied())
                                {
                                    died = true;
                                    break;
                                }
                            }
                        }

                        if (died)
                        {
                            continue;
                        }
                        if (!found)
                        {
                            ch.AffectedBy.RemoveBit((int)AffectedByTypes.RecurringSpell);
                        }
                    }

                    if (ch.MentalState >= 30)
                    {
                        var val = (ch.MentalState + 5) / 10;
                        if (HighMentalStateTable.ContainsKey(val))
                        {
                            ch.SendTo(HighMentalStateTable[val].Key);
                            comm.act(ATTypes.AT_ACTION, HighMentalStateTable[val].Value, ch, null, null, ToTypes.Room);
                        }
                    }

                    if (ch.MentalState <= -30)
                    {
                        var val = (Math.Abs(ch.MentalState) + 5) / 10;
                        if (LowMentalStateTable.ContainsKey(val))
                        {
                            if (val > 7)
                            {
                                if ((int)ch.CurrentPosition > (int)PositionTypes.Sleeping)
                                {
                                    if ((ch.CurrentPosition == PositionTypes.Standing ||
                                         (int)ch.CurrentPosition < (int)PositionTypes.Fighting) &&
                                        (SmaugRandom.D100() + (100 - val * 10) + 10 < Math.Abs(ch.MentalState)))
                                    {
                                        Sleep.do_sleep(ch, string.Empty);
                                    }
                                    else
                                    {
                                        ch.SendTo(LowMentalStateTable[val]);
                                    }
                                }
                            }
                            else
                            {
                                if ((int)ch.CurrentPosition > (int)PositionTypes.Resting)
                                {
                                    ch.SendTo(LowMentalStateTable[val]);
                                }
                            }
                        }
                    }

                    if (ch.Timer > 24)
                    {
                        Quit.do_quit(ch, string.Empty);
                    }
                    else if (ch == ch_save && GameManager.Instance.SystemData.SaveFlags.IsSet(AutoSaveFlags.Auto))
                    {
                        save.save_char_obj(ch);
                    }
                }
            }

            //trowlrd_dispose
        }
Ejemplo n.º 4
0
        public static void ModifyAffect(this CharacterInstance ch, AffectData affect, bool add)
        {
            var mod = affect.Modifier;

            if (add)
            {
                mod = ModifyAndAddAffect(ch, affect, mod);
            }
            else
            {
                ch.AffectedBy.RemoveBit((int)affect.Type);

                if ((int)affect.Location % Program.REVERSE_APPLY == (int)ApplyTypes.RecurringSpell)
                {
                    mod = Math.Abs(mod);
                    var skill = RepositoryManager.Instance.SKILLS.Values.ToList()[mod];

                    if (!Macros.IS_VALID_SN(mod) || skill == null || skill.Type != SkillTypes.Spell)
                    {
                        throw new InvalidDataException($"RecurringSpell with bad SN {mod}");
                    }
                    ch.AffectedBy.RemoveBit((int)AffectedByTypes.RecurringSpell);
                    return;
                }

                switch ((int)affect.Location % Program.REVERSE_APPLY)
                {
                case (int)ApplyTypes.Affect:
                    return;

                case (int)ApplyTypes.ExtendedAffect:
                    ch.AffectedBy.RemoveBit(mod);
                    return;

                case (int)ApplyTypes.Resistance:
                    ch.Resistance.RemoveBit(mod);
                    return;

                case (int)ApplyTypes.Immunity:
                    ch.Immunity.RemoveBit(mod);
                    return;

                case (int)ApplyTypes.Susceptibility:
                    ch.Susceptibility.RemoveBit(mod);
                    return;

                case (int)ApplyTypes.Remove:
                    return;
                }
                mod = 0 - mod;
            }

            var applyType = Common.EnumerationExtensions.GetEnum <ApplyTypes>((int)affect.Location % Program.REVERSE_APPLY);

            switch (applyType)
            {
            case ApplyTypes.Strength:
                ch.ModStrength += mod;
                break;

            case ApplyTypes.Dexterity:
                ch.ModDexterity += mod;
                break;

            case ApplyTypes.Intelligence:
                ch.ModIntelligence += mod;
                break;

            case ApplyTypes.Wisdom:
                ch.ModWisdom += mod;
                break;

            case ApplyTypes.Constitution:
                ch.ModConstitution += mod;
                break;

            case ApplyTypes.Charisma:
                ch.ModCharisma += mod;
                break;

            case ApplyTypes.Luck:
                ch.ModLuck += mod;
                break;

            case ApplyTypes.Gender:
                //ch.Gender = (ch.Gender + mod) % 3;
                // TODO Fix this
                //if (ch.Gender < 0)
                //    ch.Gender += 2;
                //ch.Gender = Check.Range(0, ch.Gender, 2);
                break;

            case ApplyTypes.Height:
                ch.Height += mod;
                break;

            case ApplyTypes.Weight:
                ch.Weight += mod;
                break;

            case ApplyTypes.Mana:
                ch.MaximumMana += mod;
                break;

            case ApplyTypes.Hit:
                ch.MaximumHealth += mod;
                break;

            case ApplyTypes.Movement:
                ch.MaximumMovement += mod;
                break;

            case ApplyTypes.ArmorClass:
                ch.ArmorClass += mod;
                break;

            case ApplyTypes.HitRoll:
                ch.HitRoll.SizeOf += mod;
                break;

            case ApplyTypes.DamageRoll:
                ch.DamageRoll.SizeOf += mod;
                break;

            case ApplyTypes.SaveVsPoison:
                ch.SavingThrows.SaveVsPoisonDeath += mod;
                break;

            case ApplyTypes.SaveVsRod:
                ch.SavingThrows.SaveVsWandRod += mod;
                break;

            case ApplyTypes.SaveVsParalysis:
                ch.SavingThrows.SaveVsParalysisPetrify += mod;
                break;

            case ApplyTypes.SaveVsBreath:
                ch.SavingThrows.SaveVsBreath += mod;
                break;

            case ApplyTypes.SaveVsSpell:
                ch.SavingThrows.SaveVsSpellStaff += mod;
                break;

            case ApplyTypes.Affect:
                ch.AffectedBy.Bits[0].SetBit(mod);
                break;

            case ApplyTypes.ExtendedAffect:
                ch.AffectedBy.SetBit(mod);
                break;

            case ApplyTypes.Resistance:
                ch.Resistance.SetBit(mod);
                break;

            case ApplyTypes.Immunity:
                ch.Immunity.SetBit(mod);
                break;

            case ApplyTypes.Susceptibility:
                ch.Susceptibility.SetBit(mod);
                break;

            case ApplyTypes.Remove:
                ch.AffectedBy.Bits[0].RemoveBit(mod);
                break;

            case ApplyTypes.Full:
            case ApplyTypes.Thirst:
            case ApplyTypes.Drunk:
            case ApplyTypes.Blood:
                HandlePlayerCondition(ch, applyType, mod);
                break;

            case ApplyTypes.MentalState:
                ch.MentalState = (ch.MentalState + mod).GetNumberThatIsBetween(-100, 100);
                break;

            case ApplyTypes.Emotion:
                ch.EmotionalState = ch.EmotionalState.GetNumberThatIsBetween(-100, 100);
                break;

            case ApplyTypes.StripSN:
                if (Macros.IS_VALID_SN(mod))
                {
                    ch.StripAffects(mod);
                }
                else
                {
                    LogManager.Instance.Bug("apply_modify: ApplyTypes.StripSN invalid SN %d", mod);
                }
                break;

            case ApplyTypes.WearSpell:
            case ApplyTypes.RemoveSpell:
                if (ch.CurrentRoom.Flags.IsSet(RoomFlags.NoMagic) ||
                    ch.Immunity.IsSet(ResistanceTypes.Magic) ||
                    (applyType == ApplyTypes.WearSpell && !add) ||
                    (applyType == ApplyTypes.RemoveSpell && add) ||
                    handler.SavingCharacter == ch ||
                    handler.LoadingCharacter == ch)
                {
                    return;
                }

                mod = Math.Abs(mod);
                var skill = RepositoryManager.Instance.SKILLS.Values.ToList()[mod];

                if (Macros.IS_VALID_SN(mod) && skill != null && skill.Type == SkillTypes.Spell)
                {
                    if (skill.Target == TargetTypes.Ignore ||
                        skill.Target == TargetTypes.InventoryObject)
                    {
                        LogManager.Instance.Bug("ApplyTypes.WearSpell trying to apply bad target spell. SN is %d.", mod);
                        return;
                    }
                    var retcode = skill.SpellFunction.Value.Invoke(mod, ch.Level, ch, ch);
                    if (retcode == ReturnTypes.CharacterDied || ch.CharDied())
                    {
                        return;
                    }
                }
                break;

            default:
                var skillData = RepositoryManager.Instance.GetEntity <SkillData>(applyType.GetName());
                if (skillData != null)
                {
                    ch.ModifySkill((int)skillData.Type, mod, add);
                }
                else
                {
                    LogManager.Instance.Bug("affect_modify: unknown location %d", affect.Location);
                }
                break;
            }

            var wield       = ch.GetEquippedItem(WearLocations.Wield);
            var strWieldMod = (int)LookupManager.Instance.GetStatMod("Strength", ch.GetCurrentStrength(),
                                                                     StrengthModTypes.Wield);

            if (!ch.IsNpc() && handler.SavingCharacter != ch && wield != null && wield.GetWeight() > strWieldMod)
            {
                if (Depth == 0)
                {
                    Depth++;
                    comm.act(ATTypes.AT_ACTION, "You are too weak to wield $p any longer.", ch, wield, null,
                             ToTypes.Character);
                    comm.act(ATTypes.AT_ACTION, "$n stops wielding $p.", ch, wield, null, ToTypes.Room);
                    ch.Unequip(wield);
                    Depth--;
                }
            }
        }