public ItemTemplateParser() { bool flag = this._holder == null; if (flag) { this._holder = ItemTemplateHolder.getInstance(); } string text = "Data//Items"; bool flag2 = Directory.Exists(text); if (flag2) { string[] files = Directory.GetFiles(text, "*.xml", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { this.parse(files[i]); } } else { CLogger.getInstance().info("[ItemTemplateParser]: No Have Dir: " + text); } bool flag3 = this._holder != null; if (flag3) { this._holder.log(); } }
public ItemTemplateParser() { if (this._holder == null) { this._holder = ItemTemplateHolder.getInstance(); } string path = "data//items"; if (Directory.Exists(path)) { string[] strArray = Directory.GetFiles(path, "*.xml", SearchOption.AllDirectories); for (int i = 0; i < strArray.Length; i++) { this.parse(strArray[i]); } } else { CLogger.getInstance().info("[ItemTemplateParser]: No Have Dir: " + path); } if (this._holder != null) { this._holder.log(); } }
public ItemHolder(ItemTemplateHolder itemTemplate) { this.itemTemplate = itemTemplate; }
public ItemHolder(ItemTemplateHolder itemTemplate) { _itemTemplate = itemTemplate; }
public CharacterCreationRequest(GameClient client, ReceivablePacket packet) { // Make sure player has authenticated. if ((client.GetAccountName() == null) || (client.GetAccountName().Length == 0)) { return; } // Read data. string characterName = packet.ReadString(); int race = packet.ReadByte(); float height = packet.ReadFloat(); float belly = packet.ReadFloat(); int hairType = packet.ReadByte(); int hairColor = packet.ReadInt(); int skinColor = packet.ReadInt(); int eyeColor = packet.ReadInt(); // Replace illegal characters. for (int i = 0; i < Util.ILLEGAL_CHARACTERS.Length; i++) { characterName = characterName.Replace(Util.ILLEGAL_CHARACTERS[i], '\''); } // Name character checks. if (characterName.Contains("'")) { client.ChannelSend(new CharacterCreationResult(INVALID_NAME)); return; } if ((characterName.Length < 2) || (characterName.Length > 12)) // 12 should not happen, checking it here in case of client cheat. { client.ChannelSend(new CharacterCreationResult(NAME_IS_TOO_SHORT)); return; } // Visual exploit checks. if ((race < 0 || race > 1) || (height < 0.39 || height > 0.61) || (hairType < 0 || hairType > 3) /*|| (!Config.VALID_SKIN_COLORS.Contains(skinColor))*/) // TODO: Check palette. { client.ChannelSend(new CharacterCreationResult(INVALID_PARAMETERS)); return; } // Account character count database check. int characterCount = 0; int lastCharacterSlot = 0; try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(ACCOUNT_CHARACTER_QUERY, con); cmd.Parameters.AddWithValue("account", client.GetAccountName()); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { characterCount++; int slot = reader.GetInt32("slot"); if (slot > lastCharacterSlot) { lastCharacterSlot = slot; } } con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } if (characterCount >= Config.ACCOUNT_MAX_CHARACTERS) { client.ChannelSend(new CharacterCreationResult(CANNOT_CREATE_ADDITIONAL_CHARACTERS)); return; } // Check database if name exists. bool characterExists = false; try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(NAME_EXISTS_QUERY, con); { cmd.Parameters.AddWithValue("name", characterName); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { characterExists = true; } } con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } if (characterExists) { client.ChannelSend(new CharacterCreationResult(NAME_ALREADY_EXISTS)); return; } // Make existing characters selected value false. try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(CHARACTER_SELECTED_RESET_QUERY, con); cmd.Parameters.AddWithValue("account", client.GetAccountName()); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } // Create character. try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(CHARACTER_CREATE_QUERY, con); cmd.Parameters.AddWithValue("account", client.GetAccountName()); cmd.Parameters.AddWithValue("name", characterName); cmd.Parameters.AddWithValue("slot", lastCharacterSlot + 1); cmd.Parameters.AddWithValue("selected", 1); // Selected character. cmd.Parameters.AddWithValue("race", race); cmd.Parameters.AddWithValue("height", height); cmd.Parameters.AddWithValue("belly", belly); cmd.Parameters.AddWithValue("hair_type", hairType); cmd.Parameters.AddWithValue("hair_color", hairColor); cmd.Parameters.AddWithValue("skin_color", skinColor); cmd.Parameters.AddWithValue("eye_color", eyeColor); cmd.Parameters.AddWithValue("x", Config.STARTING_LOCATION.GetX()); cmd.Parameters.AddWithValue("y", Config.STARTING_LOCATION.GetY()); cmd.Parameters.AddWithValue("z", Config.STARTING_LOCATION.GetZ()); cmd.Parameters.AddWithValue("heading", Config.STARTING_LOCATION.GetHeading()); cmd.Parameters.AddWithValue("experience", 0); // TODO: Implement Player level data. cmd.Parameters.AddWithValue("hp", 100); // TODO: Implement Player level data. cmd.Parameters.AddWithValue("mp", 100); // TODO: Implement Player level data. cmd.ExecuteNonQuery(); con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } // Create a character_options entry for this character. try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(CHARACTER_CREATE_OPTIONS_QUERY, con); cmd.Parameters.AddWithValue("name", characterName); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } // Add starting items. int itemCount = Config.STARTING_ITEMS.Count; if (itemCount > 0) { // Prepare query. StringBuilder query = new StringBuilder(CHARACTER_ITEM_START); List <ItemSlot> usedEquipableSlots = new List <ItemSlot>(); int inventorySlotCounter = 8; // First inventory item slot. foreach (int itemId in Config.STARTING_ITEMS) { query.Append("('"); query.Append(characterName); query.Append("',"); ItemTemplateHolder itemHolder = ItemData.GetItemTemplate(itemId); ItemSlot itemSlot = itemHolder.GetItemSlot(); if (itemHolder.GetItemType() == ItemType.EQUIP && !usedEquipableSlots.Contains(itemSlot)) { usedEquipableSlots.Add(itemSlot); query.Append((int)itemHolder.GetItemSlot()); } else { query.Append(inventorySlotCounter++); } query.Append(","); query.Append(itemId); query.Append(",1,0"); // quantity, enchant query.Append(")"); query.Append(itemCount-- == 1 ? ";" : ","); } // Store new item records. try { MySqlConnection con = DatabaseManager.GetConnection(); MySqlCommand cmd = new MySqlCommand(query.ToString(), con); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception e) { LogManager.Log(e.ToString()); } } // Send success result. client.ChannelSend(new CharacterCreationResult(SUCCESS)); }
public void EquipItem(DynamicCharacterAvatar avatar, int id) { ItemTemplateHolder item = ItemData.GetItemTemplate(id); if (item == null || item.GetItemType() != ItemType.EQUIP) { return; } // UMAData must not be null, so wait until it is not. UMAData umaData = null; while (umaData == null) { umaData = avatar.gameObject.GetComponent <UMAData>(); } bool isMale = avatar.activeRace.name.Equals("HumanMaleDCS"); switch (item.GetItemSlot()) { case ItemSlot.HEAD: avatar.SetSlot("Helmet", isMale ? item.GetRecipeMale() : item.GetRecipeFemale()); avatar.BuildCharacter(); break; case ItemSlot.CHEST: avatar.SetSlot("Chest", isMale ? item.GetRecipeMale() : item.GetRecipeFemale()); avatar.BuildCharacter(); break; case ItemSlot.LEGS: avatar.SetSlot("Legs", isMale ? item.GetRecipeMale() : item.GetRecipeFemale()); avatar.BuildCharacter(); break; case ItemSlot.HANDS: avatar.SetSlot("Hands", isMale ? item.GetRecipeMale() : item.GetRecipeFemale()); avatar.BuildCharacter(); break; case ItemSlot.FEET: avatar.SetSlot("Feet", isMale ? item.GetRecipeMale() : item.GetRecipeFemale()); avatar.BuildCharacter(); break; case ItemSlot.LEFT_HAND: UnEquipItem(avatar, ItemSlot.LEFT_HAND); // Find left hand bone. GameObject boneObjL = umaData.GetBoneGameObject("LeftHand"); // Create the item. GameObject newObjL = Instantiate(ItemData.Instance.GetItemPrefab(item.GetPrefabId())); newObjL.name = "LeftHandItem"; newObjL.transform.SetParent(boneObjL.transform, false); if (isMale) { newObjL.transform.localPosition = item.GetPositionMale(); newObjL.transform.localRotation = item.GetRotationMale(); newObjL.transform.localScale = item.GetScaleMale(); } else { newObjL.transform.localPosition = item.GetPositionFemale(); newObjL.transform.localRotation = item.GetRotationFemale(); newObjL.transform.localScale = item.GetScaleFemale(); } break; case ItemSlot.RIGHT_HAND: UnEquipItem(avatar, ItemSlot.RIGHT_HAND); // Find right hand bone. GameObject boneObjR = umaData.GetBoneGameObject("RightHand"); // Create the item. GameObject newObjR = Instantiate(ItemData.Instance.GetItemPrefab(item.GetPrefabId())); newObjR.name = "RightHandItem"; newObjR.transform.SetParent(boneObjR.transform, false); if (isMale) { newObjR.transform.localPosition = item.GetPositionMale(); newObjR.transform.localRotation = item.GetRotationMale(); newObjR.transform.localScale = item.GetScaleMale(); } else { newObjR.transform.localPosition = item.GetPositionFemale(); newObjR.transform.localRotation = item.GetRotationFemale(); newObjR.transform.localScale = item.GetScaleFemale(); } break; case ItemSlot.TWO_HAND: UnEquipItem(avatar, ItemSlot.TWO_HAND); // Find right hand bone. GameObject boneObjTH = umaData.GetBoneGameObject("RightHand"); // Create the item. GameObject newObjTH = Instantiate(ItemData.Instance.GetItemPrefab(item.GetPrefabId())); newObjTH.name = "TwoHandItem"; boneObjTH.transform.SetParent(boneObjTH.transform, false); if (isMale) { boneObjTH.transform.localPosition = item.GetPositionMale(); boneObjTH.transform.localRotation = item.GetRotationMale(); boneObjTH.transform.localScale = item.GetScaleMale(); } else { boneObjTH.transform.localPosition = item.GetPositionFemale(); boneObjTH.transform.localRotation = item.GetRotationFemale(); boneObjTH.transform.localScale = item.GetScaleFemale(); } break; } }