private void OnRecvGetInventory(IChannel channel, Message message) { CGetInventory request = message as CGetInventory; Player player = (Player)channel.GetContent(); SGetInventory response = new SGetInventory(); Console.WriteLine("Getting Inventory"); var connString = "Host=localhost;Port=5432;Username=postgres;Password=123456;Database=postgres"; var conn = new NpgsqlConnection(connString); conn.Open(); var cmd = new NpgsqlCommand(string.Format("SELECT item_name,item_num from users_items WHERE user_name = '{0}'", player.user), conn); Console.WriteLine("Select finished"); var reader = cmd.ExecuteReader(); String item_name; player.Inventory.Clear(); while (reader.Read()) { item_name = Convert.ToString(reader["item_name"]); // 获得指定字段的值 //market.item.item_type = Convert.ToString(reader["item_type"]); player.Inventory.Add(item_name, Convert.ToInt16(reader["item_num"])); } reader.Close(); /* * foreach (KeyValuePair<string, int> kvp in player.Inventory) * { * Console.Write("{0},{1}", kvp.Key, kvp.Value); * }*/ response.player_Inventory = player.Inventory; channel.Send(response); }
private void OnEnable() { PlayerMyController.Instance.EnabledWindowCount++; CGetInventory getInventory = new CGetInventory(); Client.Instance.Send(getInventory); if (m_controller == null || m_damageable == null) { m_controller = PlayerController.Mine; m_damageable = PlayerController.Mine.GetComponent <Damageable>(); } string hp = string.Format("{0}/{1}", m_damageable.currentHitPoints, m_damageable.maxHitPoints); HPValue.SetText(hp, true); InteligenceValue.SetText(Attribute.InteligenceValue, true); SpeedValue.SetText(Attribute.SpeedValue, true); LevelValue.SetText(Attribute.LevelValue, true); AttackValue.SetText(Attribute.AttackValue, true); DefenseValue.SetText(Attribute.DefenseValue, true); if (Attribute.defense_item != "0") { Sprite defense_icon = GetAllIcons.icons[Attribute.defense_item]; GameObject.Find("DefenseImage").GetComponent <Image>().sprite = defense_icon; } if (Attribute.defense_item.Equals("0")) { GameObject.Find("DefenseImage").GetComponent <Image>().sprite = null; } if (Attribute.inteligence_item != "0") { Sprite in_icon = GetAllIcons.icons[Attribute.inteligence_item]; GameObject.Find("InteligenceImage").GetComponent <Image>().sprite = in_icon; } if (Attribute.inteligence_item == "0") { GameObject.Find("InteligenceImage").GetComponent <Image>().sprite = null; } if (Attribute.attack_item != "0") { Sprite attack_icon = GetAllIcons.icons[Attribute.attack_item]; GameObject.Find("AttackImage").GetComponent <Image>().sprite = attack_icon; } if (Attribute.attack_item == "0") { GameObject.Find("AttackImage").GetComponent <Image>().sprite = null; } if (Attribute.speed_item != "0") { Sprite speed_icon = GetAllIcons.icons[Attribute.speed_item]; GameObject.Find("SpeedImage").GetComponent <Image>().sprite = speed_icon; } if (Attribute.speed_item == "0") { GameObject.Find("SpeedImage").GetComponent <Image>().sprite = null; } }
public void OnRefreshClicked() { GameObject.FindObjectOfType <RoleUI>().InteligenceValue.SetText(Attribute.InteligenceValue, true); GameObject.FindObjectOfType <RoleUI>().SpeedValue.SetText(Attribute.SpeedValue, true); GameObject.FindObjectOfType <RoleUI>().LevelValue.SetText(Attribute.LevelValue, true); GameObject.FindObjectOfType <RoleUI>().AttackValue.SetText(Attribute.AttackValue, true); GameObject.FindObjectOfType <RoleUI>().DefenseValue.SetText(Attribute.DefenseValue, true); CGetInventory getInventory = new CGetInventory(); Client.Instance.Send(getInventory); OnDisable(); OnEnable(); //GameObject.FindObjectOfType<SellingInventoryUI>().OnRefreshClicked(); }