/// <summary>Get a monster's possible drops.</summary> /// <param name="monster">The monster whose drops to get.</param> private IEnumerable <ItemDropData> GetMonsterDrops(Monster monster) { // get actual drops int[] drops = monster.objectsToDrop.ToArray(); // get possible drops ItemDropData[] possibleDrops = this.GameHelper.GetMonsterData().FirstOrDefault(p => p.Name == monster.Name)?.Drops; if (possibleDrops == null && this.IsHauntedSkull) { possibleDrops = this.GameHelper.GetMonsterData().FirstOrDefault(p => p.Name == "Lava Bat")?.Drops; // haunted skulls use lava bat data } if (possibleDrops == null) { possibleDrops = new ItemDropData[0]; } // get combined data return( from possibleDrop in possibleDrops let isGuaranteed = drops.Contains(possibleDrop.ItemID) select new ItemDropData( itemID: possibleDrop.ItemID, minDrop: 1, maxDrop: possibleDrop.MaxDrop, probability: isGuaranteed ? 1 : possibleDrop.Probability ) ); }
public static void LoadData() { if (s_ItemDropDataTbl != null) { return; } s_ItemDropDataTbl = new Dictionary <int, ItemDropData>(); SqliteDataReader reader = LocalDatabase.Instance.ReadFullTable("loot"); while (reader.Read()) { string strId = reader.GetString(reader.GetOrdinal("id")); int id = Convert.ToInt32(strId); bool validData = false; // Meat ItemDropData itemDropData = new ItemDropData(); string strMeat = reader.GetString(reader.GetOrdinal("meat")); string[] strLowerUpper = strMeat.Split(';'); if (strLowerUpper.Length == 2) { itemDropData._meatData.lower = Convert.ToInt32(strLowerUpper[0]); itemDropData._meatData.upper = Convert.ToInt32(strLowerUpper[1]); validData = true; } // Other string strTmp = reader.GetString(reader.GetOrdinal("loot")); string[] strlist0 = strTmp.Split(';'); if (strlist0.Length == 2) { int count = Convert.ToInt32(strlist0[0]); string[] stritemlist = strlist0[1].Split(','); if (count > 0 && stritemlist.Length > 0) { List <DropData> dropLst = new List <DropData>(); for (int i = 0; i < stritemlist.Length; i++) { string[] strlist1 = stritemlist[i].Split('_'); if (strlist1.Length == 2) { DropData dropData = new DropData(); dropData.id = Convert.ToInt32(strlist1[0]); dropData.pro = Convert.ToSingle(strlist1[1]); dropLst.Add(dropData); } } itemDropData._cnt = count; itemDropData._dropList = dropLst; } validData = true; } if (validData) { s_ItemDropDataTbl[id] = itemDropData; } } }
/// <summary>Draw the value (or return <c>null</c> to render the <see cref="GenericField.Value"/> using the default format).</summary> /// <param name="spriteBatch">The sprite batch being drawn.</param> /// <param name="font">The recommended font.</param> /// <param name="position">The position at which to draw.</param> /// <param name="wrapWidth">The maximum width before which content should be wrapped.</param> /// <returns>Returns the drawn dimensions, or <c>null</c> to draw the <see cref="GenericField.Value"/> using the default format.</returns> public override Vector2?DrawValue(SpriteBatch spriteBatch, SpriteFont font, Vector2 position, float wrapWidth) { if (!this.Drops.Any()) { return(spriteBatch.DrawTextBlock(font, this.DefaultText, position, wrapWidth)); } float height = 0; // draw preface if (!string.IsNullOrWhiteSpace(this.Preface)) { Vector2 prefaceSize = spriteBatch.DrawTextBlock(font, this.Preface, position, wrapWidth); height += (int)prefaceSize.Y; } // list drops Vector2 iconSize = new Vector2(font.MeasureString("ABC").Y); foreach (var entry in this.Drops) { // get data ItemDropData drop = entry.Item1; SObject item = entry.Item2; SpriteInfo sprite = entry.Item3; bool isGuaranteed = drop.Probability > .99f; bool shouldFade = this.FadeNonGuaranteed && !isGuaranteed; bool shouldCrossOut = this.CrossOutNonGuaranteed && !isGuaranteed; // draw icon spriteBatch.DrawSpriteWithin(sprite, position.X, position.Y + height, iconSize, shouldFade ? Color.White * 0.5f : Color.White); // draw text string text = isGuaranteed ? item.DisplayName : I18n.Generic_PercentChanceOf(percent: (int)(Math.Round(drop.Probability, 4) * 100), label: item.DisplayName); if (drop.MinDrop != drop.MaxDrop) { text += $" ({I18n.Generic_Range(min: drop.MinDrop, max: drop.MaxDrop)})"; } else if (drop.MinDrop > 1) { text += $" ({drop.MinDrop})"; } Vector2 textSize = spriteBatch.DrawTextBlock(font, text, position + new Vector2(iconSize.X + 5, height + 5), wrapWidth, shouldFade ? Color.Gray : Color.Black); // cross out item if it definitely won't drop if (shouldCrossOut) { spriteBatch.DrawLine(position.X + iconSize.X + 5, position.Y + height + iconSize.Y / 2, new Vector2(textSize.X, 1), this.FadeNonGuaranteed ? Color.Gray : Color.Black); } height += textSize.Y + 5; } // return size return(new Vector2(wrapWidth, height)); }
void CreateDroppableItemList() { if (_itemListsUpdated) { return; } _itemListsUpdated = true; //_itemLists.Add(this); // this will be added at the end of this method(foreach) Pathea.PeEntity entity = GetComponent <Pathea.PeEntity>(); if (null == entity) { return; } _skAlive = entity.GetCmpt <Pathea.SkAliveEntity>(); if (_skAlive == null || !_skAlive.isDead) { return; } if (Pathea.PeGameMgr.IsMulti) { return; } Pathea.CommonCmpt common = entity.GetCmpt <Pathea.CommonCmpt>(); if (common != null) { List <ItemSample> items = ItemDropData.GetDropItems(common.ItemDropId); if (common.entityProto.proto == Pathea.EEntityProto.Monster) { if (items == null) { items = GetSpecialItem.MonsterItemAdd(common.entityProto.protoId); } else { items.AddRange(GetSpecialItem.MonsterItemAdd(common.entityProto.protoId)); //特殊道具添加 } } if (items != null) { foreach (ItemSample item in items) { AddDroppableItem(item); } } } return; }
/// <summary>Draw the value (or return <c>null</c> to render the <see cref="GenericField.Value"/> using the default format).</summary> /// <param name="spriteBatch">The sprite batch being drawn.</param> /// <param name="font">The recommended font.</param> /// <param name="position">The position at which to draw.</param> /// <param name="wrapWidth">The maximum width before which content should be wrapped.</param> /// <returns>Returns the drawn dimensions, or <c>null</c> to draw the <see cref="GenericField.Value"/> using the default format.</returns> public override Vector2?DrawValue(SpriteBatch spriteBatch, SpriteFont font, Vector2 position, float wrapWidth) { if (!this.Drops.Any()) { return(spriteBatch.DrawTextBlock(font, this.DefaultText, position, wrapWidth)); } // get icon size Vector2 iconSize = new Vector2(font.MeasureString("ABC").Y); // list drops bool canReroll = Game1.player.isWearingRing(Ring.burglarsRing); float height = 0; foreach (var entry in this.Drops) { // get data ItemDropData drop = entry.Item1; SObject item = entry.Item2; SpriteInfo sprite = entry.Item3; bool isGuaranteed = drop.Probability > .99f; // draw icon spriteBatch.DrawSpriteWithin(sprite, position.X, position.Y + height, iconSize, isGuaranteed ? Color.White : Color.White * 0.5f); // draw text string text = isGuaranteed ? item.DisplayName : L10n.Generic.PercentChanceOf(percent: (int)(Math.Round(drop.Probability, 4) * 100), label: item.DisplayName); if (drop.MaxDrop > 1) { text += $" ({L10n.Generic.Range(min: 1, max: drop.MaxDrop)})"; } Vector2 textSize = spriteBatch.DrawTextBlock(font, text, position + new Vector2(iconSize.X + 5, height + 5), wrapWidth, isGuaranteed ? Color.Black : Color.Gray); // cross out item if it definitely won't drop if (!isGuaranteed && !canReroll) { spriteBatch.DrawLine(position.X + iconSize.X + 5, position.Y + height + iconSize.Y / 2, new Vector2(textSize.X, 1), Color.Gray); } height += textSize.Y + 5; } // return size return(new Vector2(wrapWidth, height)); }
public static List <ItemDropData> GetDropData(string dropString) { List <ItemDropData> dropData = new List <ItemDropData>(); string[] itemsData = dropString.Split(';'); foreach (var i in itemsData) { ItemDropData dData = new ItemDropData(); string[] iData = i.Split(':'); int id = int.Parse(iData[0]); dData.id = id; dData.probability = 1; string[] iAttributes = iData[1].Split('&'); foreach (var attr in iAttributes) { if (attr[0] == '%') { // probability attribute dData.probability = float.Parse(attr.Replace('%', ' ')); } else if (attr[0] == 'c') { // range attribute if (!attr.Contains(",")) { dData.hasRange = false; dData.fixedDropCount = int.Parse(attr.Replace('c', ' ')); } else { string[] dCount = attr.Replace('c', ' ').Split(','); dData.hasRange = true; dData.dropRange = new Range(int.Parse(dCount[0]), int.Parse(dCount[1])); } } } dropData.Add(dData); } return(dropData); }
public static List <ItemSample> GetDropItems(int id) { ItemDropData itemDropData = null; if (!s_ItemDropDataTbl.TryGetValue(id, out itemDropData)) { return(null); } List <ItemSample> ret = new List <ItemSample>(); System.Random r = new System.Random(); // Meat int n = r.Next(itemDropData._meatData.lower, itemDropData._meatData.upper); if (n > 0) { ret.Add(new ItemSample(229, n)); } // Other for (int i = 0; i < itemDropData._cnt; i++) { foreach (DropData dat in itemDropData._dropList) { float perc = (float)r.NextDouble(); if (perc < dat.pro) { if (dat.id > 0) { ItemSample item = ret.Find(it => it.protoId == dat.id); if (item == null) { ret.Add(new ItemSample(dat.id)); } else { item.stackCount += 1; } } break; } } } return(ret); }
/// <summary>Draw the value (or return <c>null</c> to render the <see cref="GenericField.Value"/> using the default format).</summary> /// <param name="spriteBatch">The sprite batch being drawn.</param> /// <param name="font">The recommended font.</param> /// <param name="position">The position at which to draw.</param> /// <param name="wrapWidth">The maximum width before which content should be wrapped.</param> /// <returns>Returns the drawn dimensions, or <c>null</c> to draw the <see cref="GenericField.Value"/> using the default format.</returns> public override Vector2?DrawValue(SpriteBatch spriteBatch, SpriteFont font, Vector2 position, float wrapWidth) { if (!this.Drops.Any()) { return(spriteBatch.DrawTextBlock(font, this.DefaultText, position, wrapWidth)); } // get icon size Vector2 iconSize = new Vector2(font.MeasureString("ABC").Y); // list drops bool canReroll = Game1.player.isWearingRing(Ring.burglarsRing); float height = 0; foreach (var entry in this.Drops) { // get data ItemDropData drop = entry.Item1; Object item = entry.Item2; bool isGuaranteed = drop.Probability > .99f; // draw icon spriteBatch.DrawIcon(item, position.X, position.Y + height, iconSize, isGuaranteed ? Color.White : Color.White * 0.5f); // draw text string text = isGuaranteed ? item.Name : $"{Math.Round(drop.Probability, 4) * 100}% chance of {item.Name}"; if (drop.MaxDrop > 1) { text += $" (1 to {drop.MaxDrop})"; } Vector2 textSize = spriteBatch.DrawTextBlock(font, text, position + new Vector2(iconSize.X + 5, height + 5), wrapWidth, isGuaranteed ? Color.Black : Color.Gray); // cross out item if it definitely won't drop if (!isGuaranteed && !canReroll) { spriteBatch.DrawLine(position.X + iconSize.X + 5, position.Y + height + iconSize.Y / 2, new Vector2(textSize.X, 1), Color.Gray); } height += textSize.Y + 5; } // return size return(new Vector2(wrapWidth, height)); }
public void RequestCreateLootItem(PeEntity entity) { if (null == entity) { return; } if (PeGameMgr.IsMulti) { return; } CommonCmpt common = entity.commonCmpt; if (common != null) { List <ItemSample> items = ItemDropData.GetDropItems(common.ItemDropId); if (common.entityProto.proto == EEntityProto.Monster) { if (items == null) { items = GetSpecialItem.MonsterItemAdd(common.entityProto.protoId); } else { items.AddRange(GetSpecialItem.MonsterItemAdd(common.entityProto.protoId)); //特殊道具添加 } } if (items != null) { for (int i = 0; i < items.Count; ++i) { AddLootItem(entity.position, items[i].protoId, items[i].stackCount); } } } }
public static void LoadAllData() { if (s_localDatabase != null) { return; } #if UNITY_EDITOR System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); #endif s_localDatabase = LoadDb(); SkillSystem.SkData.LoadData(); Pathea.Effect.EffectData.LoadData(); Pathea.Projectile.ProjectileData.LoadData(); Pathea.RequestRelation.LoadData(); Pathea.CampData.LoadData(); Pathea.ThreatData.LoadData(); Pathea.DamageData.LoadData(); HumanSoundData.LoadData(); ItemDropData.LoadData(); PELocalization.LoadData(); NaturalResAsset.NaturalRes.LoadData(); //SkillAsset.EffCastData.LoadData(); //SkillAsset.EffSkill.LoadData(); //SkillAsset.MergeSkill.LoadData(); //AnimData.LoadData(); //AnimSoundData.LoadData(); AiAsset.AiData.LoadData(); SoundAsset.SESoundBuff.LoadData(); SoundAsset.SESoundStory.LoadData(); //CharacterData.LoadCharacterData(); StoryDoodadMap.LoadData(); StoreRepository.LoadData(); NpcMissionDataRepository.LoadData(); //PlayerAttribute.LoadData(); MissionRepository.LoadData(); TalkRespository.LoadData(); //NpcRandomRepository.LoadData(); ShopRespository.LoadData(); WareHouseManager.LoadData(); //HeroTalkRepository.LoadData(); MutiPlayRandRespository.LoadData(); PromptRepository.LoadData(); //MapIconData.LoadDate(); //MapMaskData.LoadDate(); CampPatrolData.LoadDate(); Camp.LoadData(); RepProcessor.LoadData(); CloudManager.LoadData(); //BattleUnitData.LoadData(); TutorialData.LoadData(); //RepairMachineManager.LoadData(); MapMaskData.LoadDate(); MessageData.LoadData(); //lz-2016.07.13 Add it MonsterHandbookData.LoadData(); //lz-2016.07.20 Add it StoryRepository.LoadData(); RMRepository.LoadRandMission(); MisInitRepository.LoadData(); CameraRepository.LoadCameraPlot(); AdRMRepository.LoadData(); VCConfig.InitConfig(); Cutscene.LoadData(); // BuildBrushData.LoadBrush(); BSPattern.LoadBrush(); BSVoxelMatMap.Load(); BSBlockMatMap.Load(); BlockBuilding.LoadBuilding(); LifeFormRule.LoadData(); PlantInfo.LoadData(); MetalScanData.LoadData(); BattleConstData.LoadData(); CustomCharactor.CustomMetaData.LoadData(); SkillTreeInfo.LoadData(); VArtifactUtil.LoadData(); Pathea.ActionRelationData.LoadActionRelation(); //colony CSInfoMgr.LoadData(); ProcessingObjInfo.LoadData(); CSTradeInfoData.LoadData(); CampTradeIdData.LoadData(); AbnormalTypeTreatData.LoadData(); CSMedicineSupport.LoadData(); //RandomItemMgr RandomItemDataMgr.LoadData(); FecesData.LoadData(); //randomdungeon RandomDungeonDataBase.LoadData(); AbnormalData.LoadData(); PEAbnormalNoticeData.LoadData(); RelationInfo.LoadData(); EquipSetData.LoadData(); SuitSetData.LoadData(); CheatData.LoadData(); Pathea.NpcProtoDb.Load(); Pathea.MonsterProtoDb.Load(); Pathea.MonsterRandomDb.Load(); Pathea.MonsterGroupProtoDb.Load(); Pathea.RandomNpcDb.Load(); Pathea.PlayerProtoDb.Load(); Pathea.TowerProtoDb.Load(); Pathea.DoodadProtoDb.Load(); Pathea.AttPlusNPCData.Load(); Pathea.AttPlusBuffDb.Load(); Pathea.NpcTypeDb.Load(); Pathea.NpcRandomTalkDb.Load(); Pathea.NpcThinkDb.LoadData(); Pathea.NpcEatDb.LoadData(); Pathea.NpcRobotDb.Load(); Pathea.NPCScheduleData.Load(); Pathea.NpcVoiceDb.LoadData(); InGameAidData.LoadData(); //lz-2016.08.21 add it MountsSkillDb.LoadData(); #if UNITY_EDITOR sw.Stop(); Debug.Log("Database Loaded : " + sw.ElapsedMilliseconds); sw.Reset(); #else Debug.Log("Database Loaded"); #endif }