public void KeyDown(int key)
    {
        if (keyContactData == null || iPlayerState == null || iGameState == null || playerState == null)
        {
            return;
        }
        if (iGameState.GameRunType != EnumGameRunType.Unsafa && iGameState.GameRunType != EnumGameRunType.Safe)
        {
            return;
        }
        KeyContactStruct[] keyContactStructs = keyContactData.GetKeyContactStruct(key, temp => temp.keyContactType == EnumKeyContactType.Prap, iPlayerState.KeyContactDataZone);
        if (keyContactStructs.Length == 0)
        {
            return;
        }
        KeyContactStruct keyContactStruct = keyContactStructs[0];
        PlayGoods        playGoods        = playerState.PlayerAllGoods.Where(temp => temp.ID == keyContactStruct.id).FirstOrDefault();

        if (playGoods == null)
        {
            return;
        }
        //暂时这么写
        if (playGoods.GoodsInfo.EnumGoodsType == EnumGoodsType.HFYJ)
        {
            iPlayerState.EatMedicine(playGoods.ID);
        }
    }
Beispiel #2
0
 /// <summary>
 /// 开始道具的功能
 /// 如果是装备则替换,如果是药水则恢复
 /// </summary>
 private void ItemAction()
 {
     if (focusUIListItem)
     {
         //物品对象
         PlayGoods     playGoods     = (PlayGoods)focusUIListItem.value;
         EnumGoodsType enumGoodsType = playGoods.GoodsInfo.EnumGoodsType;
         int           goodsTypeInt  = (int)enumGoodsType;
         if (GoodsStaticTools.IsChildGoodsNode(enumGoodsType, EnumGoodsType.Equipment))//如果是装备类型则替换装备
         {
             //如果是副手武器
             if (GoodsStaticTools.IsLeftOneHandedWeapon(enumGoodsType))
             {
                 //需要判断当前是否佩戴了双手武器以及副手武器(左手武器),如果佩戴了则需要卸载双手武器
                 PlayGoods[] twoHandedWeapons = playerState.PlayerAllGoods.Where(
                     temp => temp.GoodsLocation == GoodsLocation.Wearing &&
                     (GoodsStaticTools.IsTwoHandedWeapon(temp.GoodsInfo.EnumGoodsType) ||
                      (temp.leftRightArms != null && temp.leftRightArms.Value == false))).ToArray();
                 foreach (PlayGoods _playGoods in twoHandedWeapons)
                 {
                     _playGoods.leftRightArms = null;
                     _playGoods.GoodsLocation = GoodsLocation.Package;
                 }
                 playGoods.leftRightArms = false;
             }
             //如果是双手武器
             else if (GoodsStaticTools.IsTwoHandedWeapon(enumGoodsType))
             {
                 //需要判断当前是否佩戴了副手武器以及主手武器(右手武器),如果佩戴了则需要卸载副手武器
                 PlayGoods[] oneHandedWeapons = playerState.PlayerAllGoods.Where(
                     temp => temp.GoodsLocation == GoodsLocation.Wearing &&
                     (GoodsStaticTools.IsLeftOneHandedWeapon(temp.GoodsInfo.EnumGoodsType) ||
                      (temp.leftRightArms != null && temp.leftRightArms.Value == true))).ToArray();
                 foreach (PlayGoods _playGoods in oneHandedWeapons)
                 {
                     _playGoods.leftRightArms = null;
                     _playGoods.GoodsLocation = GoodsLocation.Package;
                 }
                 playGoods.leftRightArms = true;
             }
             //如果是饰品
             else if (GoodsStaticTools.IsChildGoodsNode(enumGoodsType, EnumGoodsType.Ornaments))
             {
                 EnumGoodsType?ornamentsType = GoodsStaticTools.GetParentGoodsType(playGoods.GoodsInfo.EnumGoodsType); //从基础的饰品类型向上跳到饰品的分类类型(项链 戒指 护身符 勋章)
                 if (ornamentsType != null && GoodsStaticTools.IsChildGoodsNode(ornamentsType.Value, EnumGoodsType.Ornaments))
                 {
                     PlayGoods[] ornaments = playerState.PlayerAllGoods.Where(
                         temp => temp.GoodsLocation == GoodsLocation.Wearing && GoodsStaticTools.IsChildGoodsNode(temp.GoodsInfo.EnumGoodsType, ornamentsType.Value)).ToArray();
                     foreach (PlayGoods _playGoods in ornaments)
                     {
                         _playGoods.GoodsLocation = GoodsLocation.Package;
                     }
                 }
             }
             //如果是武器(这里是单手武器,双手武器以及副手在上面已经判断过了 )
             else if (GoodsStaticTools.IsChildGoodsNode(enumGoodsType, EnumGoodsType.Arms))
             {
                 //需要卸载所有的右手装备
                 PlayGoods[] rightHandedWeapons = playerState.PlayerAllGoods.Where(
                     temp => temp.GoodsLocation == GoodsLocation.Wearing && temp.leftRightArms != null && temp.leftRightArms.Value == true).ToArray();
                 foreach (PlayGoods _playGoods in rightHandedWeapons)
                 {
                     _playGoods.leftRightArms = null;
                     _playGoods.GoodsLocation = GoodsLocation.Package;
                 }
                 playGoods.leftRightArms = true;
             }
             //如果是其他装备(防具等)
             else
             {
                 EnumGoodsType?armorType = GoodsStaticTools.GetParentGoodsType(playGoods.GoodsInfo.EnumGoodsType, 2); //从基础的防具类型向上跳到防具的大类(头盔大类 盔甲类 鞋子类)
                 if (armorType != null && GoodsStaticTools.IsChildGoodsNode(armorType.Value, EnumGoodsType.Equipment))
                 {
                     PlayGoods[] ammors = playerState.PlayerAllGoods.Where(
                         temp => temp.GoodsLocation == GoodsLocation.Wearing && GoodsStaticTools.IsChildGoodsNode(temp.GoodsInfo.EnumGoodsType, armorType.Value)).ToArray();
                     foreach (PlayGoods _playGoods in ammors)
                     {
                         _playGoods.GoodsLocation = GoodsLocation.Package;
                     }
                 }
             }
             playGoods.GoodsLocation          = GoodsLocation.Wearing;
             iPlayerStateRun.EquipmentChanged = true;
         }
         else if (GoodsStaticTools.IsChildGoodsNode(enumGoodsType, EnumGoodsType.Elixir))//如果是炼金药剂类则直接服用
         {
             iPlayerStateRun.EatMedicine(playGoods.ID);
         }
         else if (GoodsStaticTools.IsChildGoodsNode(enumGoodsType, EnumGoodsType.Item)) //如果是道具
         {
             if (enumGoodsType == EnumGoodsType.MagicScroll)                            //此处的魔法卷轴有一个任务的特殊检测
             {
                 INowTaskState iNowTaskState = GameState.Instance.GetEntity <INowTaskState>();
                 iNowTaskState.CheckNowTask(EnumCheckTaskType.Special, (int)TaskMap.Enums.EnumTaskSpecialCheck.SummonsScrollMagic);
             }
             Debug.Log("道具功能暂未实现");
         }
     }
 }