예제 #1
0
        public int CalculateTotal(EmbeddedData data, DbChar character, DbClassStats stats, out bool firstBorn)
        {
            double f = 0;

            foreach (var i in bonusDat)
            {
                if (i.Item3(this, character, character.Fame))
                {
                    f += i.Item4(character.Fame);
                }
            }

            //Well Equiped
            var bonus = character.Items.Take(4).Where(x => x != -1).Sum(x => data.Items[(ushort)x].FameBonus) / 100.0;

            f += character.Fame * bonus;

            //First born
            if (character.Fame + bonus > stats.AllKeys.Select(x => stats[ushort.Parse(x)].BestFame).Max())
            {
                bonus    += (int)(character.Fame * 0.1);
                firstBorn = true;
            }
            else
            {
                firstBorn = false;
            }

            return(character.Fame + (int)bonus);
        }
예제 #2
0
        public int CalculateTotal(EmbeddedData data, DbChar character, bool firstBorn)
        {
            double f = 0;

            foreach (var i in bonusDat)
            {
                if (i.Item3(this, character, character.Fame))
                {
                    f += i.Item4(character.Fame);
                }
            }

            //Well Equiped
            var bonus = character.Items.Take(4).Where(x => x != -1).Sum(x => data.Items[(ushort)x].FameBonus) / 100.0;

            f += character.Fame * bonus;

            //First born
            if (firstBorn)
            {
                bonus += (int)(character.Fame * 0.1);
            }

            return(character.Fame + (int)bonus);
        }
예제 #3
0
        public void Death(EmbeddedData dat, DbAccount acc, DbChar character, FameStats stats, string killer)
        {
            character.Dead = true;
            SaveCharacter(acc, character, acc.LockToken != null);
            var finalFame = stats.CalculateTotal(dat, character, new DbClassStats(acc), out bool firstBorn);
            var death     = new DbDeath(acc, character.CharId)
            {
                ObjectType = character.ObjectType,
                Level      = character.Level,
                TotalFame  = finalFame,
                Killer     = killer,
                FirstBorn  = firstBorn,
                DeathTime  = DateTime.Now
            };

            death.Flush();

            var idBuff = BitConverter.GetBytes(character.CharId);

            Sets.Remove(0, $"alive.{acc.AccountId}", idBuff);
            Lists.AddFirst(0, $"dead.{acc.AccountId}", idBuff);

            UpdateFame(acc, finalFame);

            var entry = new DbLegendEntry()
            {
                AccId     = int.Parse(acc.AccountId),
                ChrId     = character.CharId,
                TotalFame = finalFame
            };

            DbLegend.Insert(this, death.DeathTime, entry);
        }
예제 #4
0
        public void Death(EmbeddedData dat, DbAccount acc, DbChar character, FameStats stats, string killer)
        {
            character.Dead = true;
            SaveCharacter(acc, character, acc.LockToken != null);
            var finalFame = stats.CalculateTotalFame(dat, new DbClassStats(acc), character, character.Fame, out bool firstBorn);
            var death     = new DbDeath(acc, character.CharId)
            {
                ObjectType = character.ObjectType,
                Level      = character.Level,
                TotalFame  = finalFame,
                Killer     = killer,
                FirstBorn  = firstBorn,
                DeathTime  = DateTime.UtcNow
            };

            death.FlushAsync();

            var idBuff = BitConverter.GetBytes(character.CharId);

            _db.SetRemoveAsync("alive." + acc.AccountId, idBuff, CommandFlags.FireAndForget);
            _db.ListLeftPushAsync("dead." + acc.AccountId, idBuff, When.Always, CommandFlags.FireAndForget);

            UpdateFame(acc, finalFame, true);

            if (acc.AccountType <= (int)AccountType.VIP)
            {
                DbLegend.Insert(_db, int.Parse(acc.AccountId), character.CharId, finalFame);
            }
        }
예제 #5
0
 internal AutoAssign(EmbeddedData dat)
     : base("autoId")
 {
     this.dat     = dat;
     nextSignedId = GetValue <int>("nextSigned", "50000"); //0xC350
     nextFullId   = GetValue <int>("nextFull", "58000");   //0xE290
 }
예제 #6
0
        public CreateStatus CreateCharacter(EmbeddedData dat, DbAccount acc, ushort type, int skin, out DbChar character)
        {
            var @class = dat.ObjectTypeToElement[type];

            if (_db.SetLength("alive." + acc.AccountId) >= acc.MaxCharSlot)
            {
                character = null;
                return(CreateStatus.ReachCharLimit);
            }

            var newId = (int)_db.HashIncrement(acc.Key, "nextCharId");

            character = new DbChar(acc, newId)
            {
                //LootCaches = new LootCache[] { },
                ObjectType      = type,
                Level           = 1,
                Experience      = 0,
                FakeExperience  = 0,
                IsFakeEnabled   = true,
                Bless1          = false,
                Bless2          = false,
                Bless3          = false,
                Bless4          = false,
                Bless5          = false,
                EnablePetAttack = true,
                Fame            = 0,
                HasBackpack     = false,
                Items           = @class.Element("Equipment").Value.Replace("0xa22", "-1").CommaToArray <int>(),
                Stats           = new int[] {
                    int.Parse(@class.Element("MaxHitPoints").Value),
                    int.Parse(@class.Element("MaxMagicPoints").Value),
                    int.Parse(@class.Element("Attack").Value),
                    int.Parse(@class.Element("Defense").Value),
                    int.Parse(@class.Element("Speed").Value),
                    int.Parse(@class.Element("Dexterity").Value),
                    int.Parse(@class.Element("HpRegen").Value),
                    int.Parse(@class.Element("MpRegen").Value),
                },
                HP         = int.Parse(@class.Element("MaxHitPoints").Value),
                MP         = int.Parse(@class.Element("MaxMagicPoints").Value),
                Tex1       = 0,
                Tex2       = 0,
                Skin       = skin,
                Pet        = 0,
                FameStats  = new byte[0],
                TaskStats  = string.Empty,
                CreateTime = DateTime.UtcNow,
                LastSeen   = DateTime.UtcNow
            };
            character.FlushAsync();
            _db.SetAdd("alive." + acc.AccountId, BitConverter.GetBytes(newId));
            return(CreateStatus.OK);
        }
예제 #7
0
        public void Init(EmbeddedData data)
        {
            ObjectDesc field = null;

            foreach (var i in data.ObjectDescs.Where(_ => _.Value.Player || _.Value.Class == "Player"))
            {
                field = i.Value;
                SetValue(field.ObjectType.ToString(), JsonConvert.SerializeObject(new DbClassAvailabilityEntry()
                {
                    Id         = field.ObjectId,
                    Restricted = field.ObjectType == 782 ? "unrestricted" : "restricted"
                }));
            }
        }
예제 #8
0
        public CreateStatus CreateCharacter(EmbeddedData dat, DbAccount acc, ushort type, int skin, out DbChar character)
        {
            var @class = dat.ObjectTypeToElement[type];

            if (Sets.GetLength(0, "alive." + acc.AccountId).Exec() >= acc.MaxCharSlot)
            {
                character = null;
                return(CreateStatus.ReachCharLimit);
            }

            int newId = (int)Hashes.Increment(0, acc.Key, "nextCharId").Exec();

            character = new DbChar(acc, newId)
            {
                ObjectType  = type,
                Level       = 1,
                Experience  = 0,
                Fame        = 0,
                HasBackpack = false,
                Items       = @class.Element("Equipment").Value.Replace("0xa22", "-1").CommaToArray <int>(),
                Stats       = new int[] {
                    int.Parse(@class.Element("MaxHitPoints").Value),
                    int.Parse(@class.Element("MaxMagicPoints").Value),
                    int.Parse(@class.Element("Attack").Value),
                    int.Parse(@class.Element("Defense").Value),
                    int.Parse(@class.Element("Speed").Value),
                    int.Parse(@class.Element("Dexterity").Value),
                    int.Parse(@class.Element("HpRegen").Value),
                    int.Parse(@class.Element("MpRegen").Value),
                },
                HP         = int.Parse(@class.Element("MaxHitPoints").Value),
                MP         = int.Parse(@class.Element("MaxMagicPoints").Value),
                Tex1       = 0,
                Tex2       = 0,
                Skin       = skin,
                Pet        = 0,
                FameStats  = new byte[0],
                TaskStats  = string.Empty,
                CreateTime = DateTime.Now,
                LastSeen   = DateTime.Now
            };
            character.Flush();
            Sets.Add(0, "alive." + acc.AccountId, BitConverter.GetBytes(newId));
            return(CreateStatus.OK);
        }
예제 #9
0
        public void ChangeClassAvailability(DbAccount acc, EmbeddedData data, ushort type)
        {
            int price;

            if (acc.Credits < (price = data.ObjectDescs[type].UnlockCost))
            {
                return;
            }

            Hashes.Set(0, $"classAvailability.{acc.AccountId}", type.ToString(),
                       JsonConvert.SerializeObject(new DbClassAvailabilityEntry()
            {
                Id         = data.ObjectTypeToId[type],
                Restricted = "unrestricted"
            }));
            UpdateCredit(acc, -price);
            Update(acc);
        }
예제 #10
0
        public IEnumerable <Tuple <string, string, double> > GetBonuses(EmbeddedData data, DbChar character, bool firstBorn)
        {
            foreach (var i in bonusDat)
            {
                if (i.Item3(this, character, character.Fame))
                {
                    yield return(Tuple.Create(i.Item1, i.Item2, i.Item4(character.Fame)));
                }
            }

            //Well Equiped
            var bonus = character.Items.Take(4).Where(x => x != -1).Sum(x => data.Items[(ushort)x].FameBonus) / 100.0;

            if (bonus > 0)
            {
                yield return(Tuple.Create("Well Equipped", "Bonus for equipment", character.Fame * bonus));
            }

            //First born
            if (firstBorn)
            {
                yield return(Tuple.Create("First Born", "Best fame of any of your previous incarnations", character.Fame * 0.1));
            }
        }
예제 #11
0
        public int CalculateTotalFame(EmbeddedData data, DbClassStats stats, DbChar chr, int baseFame, out bool firstBorn)
        {
            double bonus = 0;

            //Ancestor
            if (chr.CharId < 2)
            {
                bonus = Math.Floor(bonus) + ((baseFame + Math.Floor(bonus)) * 0.1) + 20;
            }

            //Pacifist
            if (ShotsThatDamage == 0)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.25;
            }

            //Thirsty
            if (PotionsDrunk == 0)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.25;
            }

            //Mundane
            if (SpecialAbilityUses == 0)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.25;
            }

            //Boots on the Ground
            if (Teleports == 0)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.25;
            }

            //Tunnel Rat
            if (PirateCavesCompleted > 0 && UndeadLairsCompleted > 0 && AbyssOfDemonsCompleted > 0 && SnakePitsCompleted > 0 && SpiderDensCompleted > 0 &&
                SpriteWorldsCompleted > 0 && TombsCompleted > 0 && TrenchesCompleted > 0 && JunglesCompleted > 0 && ManorsCompleted > 0)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            //Enemy of the Gods
            if ((double)GodKills / (GodKills + MonsterKills) > 0.1)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            //Slayer of the Gods
            if ((double)GodKills / (GodKills + MonsterKills) > 0.5)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            //Oryx Slayer
            if (OryxKills > 0)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            //Accurate
            if ((double)ShotsThatDamage / Shots > 0.25)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            //Sharpshooter
            if ((double)ShotsThatDamage / Shots > 0.5)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            //Sniper
            if ((double)ShotsThatDamage / Shots > 0.75)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            //Explorer
            if (TilesUncovered > 1000000)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.05;
            }

            //Cartographer
            if (TilesUncovered > 4000000)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.05;
            }

            //Team Player
            if (LevelUpAssists > 100)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            //Leader of Men
            if (LevelUpAssists > 1000)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            //Doer of Deeds
            if (QuestsCompleted > 1000)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            //Friend of the Cubes
            if (CubeKills == 0)
            {
                bonus = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
            }

            double eq = 0;

            //Well Equipped
            for (int i = 0; i < 4; i++)
            {
                if (chr.Items[i] == -1)
                {
                    continue;
                }

                var b = data.Items[(ushort)chr.Items[i]].FameBonus;

                if (b > 0)
                {
                    eq += (baseFame + Math.Floor(bonus)) * b / 100;
                }
            }

            bonus = Math.Floor(bonus) + Math.Floor(eq);

            if (baseFame + Math.Floor(bonus) > stats.AllKeys.Select(x => stats[ushort.Parse(x)].BestFame).Max())
            {
                bonus     = Math.Floor(bonus) + (baseFame + Math.Floor(bonus)) * 0.1;
                firstBorn = true;
            }
            else
            {
                firstBorn = false;
            }

            return((int)(baseFame + Math.Floor(bonus)));
        }