Example #1
0
        public static void AddMapBuffValues(Character chr, Packet pw, BuffValueTypes pBuffFlags = BuffValueTypes.ALL)
        {
            CharacterPrimaryStats ps   = chr.PrimaryStats;
            long           currentTime = MasterThread.CurrentTime;
            BuffValueTypes added       = 0;

            int tmp = pw.Position;

            pw.WriteUInt(0); // Placeholder

            ps.BuffSpeed.EncodeForRemote(ref added, currentTime, stat => pw.WriteByte((byte)stat.N), pBuffFlags);
            ps.BuffComboAttack.EncodeForRemote(ref added, currentTime, stat => pw.WriteByte((byte)stat.N), pBuffFlags);
            ps.BuffCharges.EncodeForRemote(ref added, currentTime, stat => pw.WriteInt(stat.R), pBuffFlags);
            ps.BuffStun.EncodeForRemote(ref added, currentTime, stat => pw.WriteInt(stat.R), pBuffFlags);
            ps.BuffDarkness.EncodeForRemote(ref added, currentTime, stat => pw.WriteInt(stat.R), pBuffFlags);
            ps.BuffSeal.EncodeForRemote(ref added, currentTime, stat => pw.WriteInt(stat.R), pBuffFlags);
            ps.BuffWeakness.EncodeForRemote(ref added, currentTime, stat => pw.WriteInt(stat.R), pBuffFlags);
            ps.BuffPoison.EncodeForRemote(ref added, currentTime, stat =>
            {
                pw.WriteShort(stat.N);
                pw.WriteInt(stat.R);
            }, pBuffFlags);
            ps.BuffSoulArrow.EncodeForRemote(ref added, currentTime, null, pBuffFlags);
            ps.BuffShadowPartner.EncodeForRemote(ref added, currentTime, null, pBuffFlags);
            ps.BuffDarkSight.EncodeForRemote(ref added, currentTime, null, pBuffFlags);

            pw.SetUInt(tmp, (uint)added);
        }
 private static bool canWearItem(Character chr, CharacterPrimaryStats stats, EquipData data, short slot)
 {
     // Non-cash item on cash item slot
     if (!data.Cash && slot > 100)
     {
         return(false);
     }
     // Cash item on non-cash item slot
     else if (data.Cash && slot > 0 && slot < 100)
     {
         return(false);
     }
     else if (!Constants.IsCorrectBodyPart(data.ID, data.Cash ? (short)(slot - 100) : slot, chr.Gender))
     {
         return(false);
     }
     else
     {
         return(stats.getTotalStr() >= data.RequiredStrength &&
                stats.getTotalDex() >= data.RequiredDexterity &&
                stats.getTotalInt() >= data.RequiredIntellect &&
                stats.getTotalLuk() >= data.RequiredLuck &&
                (stats.Fame >= data.RequiredFame || data.RequiredFame == 0) &&
                stats.Level >= data.RequiredLevel &&
                isRequiredJob(Constants.getJobTrack(stats.Job), data.RequiredJob));
     }
 }
Example #3
0
 public DamageLogState(CharacterPrimaryStats primaryStats)
 {
     level    = primaryStats.Level;
     totalStr = primaryStats.TotalStr;
     totalDex = primaryStats.TotalDex;
     totalInt = primaryStats.TotalInt;
     totalLuk = primaryStats.TotalLuk;
     totalPAD = primaryStats.TotalPAD;
     totalMAD = primaryStats.TotalMAD;
     //totalPDD = primaryStats.TotalPDD;
     //totalMDD = primaryStats.TotalMDD;
     totalACC   = primaryStats.TotalACC;
     totalEVA   = primaryStats.TotalEVA;
     totalCraft = primaryStats.TotalCraft;
     totalSpeed = primaryStats.TotalSpeed;
 }
Example #4
0
        public LoadFailReasons Load(string IP)
        {
            var imitateId  = RedisBackend.Instance.GetImitateID(ID);
            var imitating  = imitateId.HasValue;
            var originalId = ID;

            if (imitating)
            {
                ID = imitateId.Value;
                _characterLog.Debug($"Loading character {ID} from IP {IP}... (IMITATION from ID {originalId})");
            }
            else
            {
                _characterLog.Debug($"Loading character {ID} from IP {IP}...");
            }

            // Initial load

            using (var data = (MySqlDataReader)Server.Instance.CharacterDatabase.RunQuery(
                       "SELECT " +
                       "characters.*, users.admin, users.superadmin, users.donator, users.beta, users.last_ip, users.online " +
                       "FROM characters " +
                       "LEFT JOIN users ON users.id = characters.userid " +
                       "WHERE characters.id = @id",
                       "@id", originalId))
            {
                if (!data.Read())
                {
                    _characterLog.Debug("Loading failed: unknown character.");
                    return(LoadFailReasons.UnknownCharacter);
                }

                if (data.GetString("last_ip") != IP && !imitating)
                {
#if DEBUG
                    Program.MainForm.LogAppend("Allowed player " + this.ID +
                                               " to log in from different IP because source is running in debug mode!");
#else
                    _characterLog.Debug("Loading failed: not from previous IP.");
                    return(LoadFailReasons.NotFromPreviousIP);
#endif
                }
                UserID     = data.GetInt32("userid");
                Name       = data.GetString("name");
                GMLevel    = data.GetByte("admin");
                Donator    = data.GetBoolean("donator");
                BetaPlayer = data.GetBoolean("beta");


                if (imitating)
                {
                    ImitatorName = Name;
                }
                else
                {
                    ImitatorName = null;
                }
            }

            var tmpUserId = UserID;

            using (var data = (MySqlDataReader)Server.Instance.CharacterDatabase.RunQuery(
                       "SELECT " +
                       "characters.*, users.last_ip, users.online, users.quiet_ban_expire, users.quiet_ban_reason " +
                       "FROM characters " +
                       "LEFT JOIN users ON users.id = characters.userid " +
                       "WHERE characters.id = @id",
                       "@id", ID))
            {
                if (!data.Read())
                {
                    _characterLog.Debug("Loading failed: unknown character.");
                    if (imitating)
                    {
                        // Reset!
                        RedisBackend.Instance.SetImitateID(originalId, 0);
                    }

                    return(LoadFailReasons.UnknownCharacter);
                }

                UserID = data.GetInt32("userid"); // For cashitem loading
                Name   = data.GetString("name");

                Gender           = data.GetByte("gender");
                Skin             = data.GetByte("skin");
                Hair             = data.GetInt32("hair");
                Face             = data.GetInt32("eyes");
                PetCashId        = data.GetInt64("pet_cash_id");
                MutedUntil       = data.GetDateTime("quiet_ban_expire");
                MuteReason       = data.GetByte("quiet_ban_reason");
                LastSavepoint    = data.GetDateTime("last_savepoint");
                LastPlayTimeSave = MasterThread.CurrentTime;

                var _mapId = data.GetInt32("map");

                Map field;
                if (!DataProvider.Maps.TryGetValue(_mapId, out field))
                {
                    Program.MainForm.LogAppend(
                        "The map of {0} is not valid (nonexistant)! Map was {1}. Returning to 0", ID, _mapId);
                    field       = DataProvider.Maps[0];
                    MapPosition = 0;
                }
                Field = field;

                // Push back player when there's a forced return value
                if (field.ForcedReturn != Constants.InvalidMap)
                {
                    _mapId = field.ForcedReturn;
                    if (!DataProvider.Maps.TryGetValue(_mapId, out field))
                    {
                        Program.MainForm.LogAppend(
                            "The map of {0} is not valid (nonexistant)! Map was {1}. Returning to 0", ID, _mapId);
                        // Note: using Field here
                        Field = DataProvider.Maps[0];
                    }
                    else
                    {
                        Field = DataProvider.Maps[_mapId];
                    }
                    MapPosition = 0;
                }
                else
                {
                    MapPosition = (byte)data.GetInt16("pos");
                }

                // Select portal to spawn on.
                {
                    Portal portal = Field.SpawnPoints.Find(x => x.ID == MapPosition);
                    if (portal == null)
                    {
                        portal = Field.GetRandomStartPoint();
                    }
                    Position = new Pos(portal.X, portal.Y);
                }
                Stance   = 0;
                Foothold = 0;

                CalcDamageRandomizer = new Rand32();
                RndActionRandomizer  = new Rand32();


                PrimaryStats = new CharacterPrimaryStats(this)
                {
                    Level             = data.GetByte("level"),
                    Job               = data.GetInt16("job"),
                    Str               = data.GetInt16("str"),
                    Dex               = data.GetInt16("dex"),
                    Int               = data.GetInt16("int"),
                    Luk               = data.GetInt16("luk"),
                    HP                = data.GetInt16("chp"),
                    MaxHP             = data.GetInt16("mhp"),
                    MP                = data.GetInt16("cmp"),
                    MaxMP             = data.GetInt16("mmp"),
                    AP                = data.GetInt16("ap"),
                    SP                = data.GetInt16("sp"),
                    EXP               = data.GetInt32("exp"),
                    Fame              = data.GetInt16("fame"),
                    BuddyListCapacity = data.GetInt32("buddylist_size")
                };

                // Make sure we don't update too many times
                lastSaveStep = CalculateSaveStep();
            }

            Inventory = new CharacterInventory(this);
            Inventory.LoadInventory();

            UserID = tmpUserId;

            Ring.LoadRings(this);

            Skills = new CharacterSkills(this);
            Skills.LoadSkills();

            Storage = new CharacterStorage(this);
            Storage.Load();

            Buffs = new CharacterBuffs(this);

            Summons = new CharacterSummons(this);

            Quests = new CharacterQuests(this);
            Quests.LoadQuests();

            Variables = new CharacterVariables(this);
            Variables.Load();

            GameStats = new CharacterGameStats(this);
            GameStats.Load();

            Wishlist = new List <int>();
            using (var data = (MySqlDataReader)Server.Instance.CharacterDatabase.RunQuery("SELECT serial FROM character_wishlist WHERE charid = " + ID))
            {
                while (data.Read())
                {
                    Wishlist.Add(data.GetInt32(0));
                }
            }

            // Loading done, switch back ID
            ID = originalId;

            InitDamageLog();

            SetIncExpRate();

            var muteTimeSpan = RedisBackend.Instance.GetCharacterMuteTime(ID);
            if (muteTimeSpan.HasValue)
            {
                HacklogMuted = MasterThread.CurrentDate.Add(muteTimeSpan.Value);
            }
            else
            {
                HacklogMuted = DateTime.MinValue;
            }

            Undercover = RedisBackend.Instance.IsUndercover(ID);

            RedisBackend.Instance.SetPlayerOnline(
                UserID,
                Server.Instance.GetOnlineId()
                );

            _characterLog.Debug("Loaded!");
            return(LoadFailReasons.None);
        }