コード例 #1
0
ファイル: RogueMain.cs プロジェクト: abotkugyu/hod
    private void ItemMenuAction(CharacterPresenter characterPresenter)
    {
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            menuPresenter.itemMenuPresenter.ChangeSelectedItem(1);
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            menuPresenter.itemMenuPresenter.ChangeSelectedItem(-1);
        }
        else if (Input.GetKeyDown(KeyCode.X))
        {
            if (characterPresenter.itemModels.Count > 0)
            {
                ItemModel item = menuPresenter.itemMenuPresenter.GetSelectedItemModel();

                // アイテム使用、削除
                characterPresenter.status.hp -= 10;
                characterPresenter.characterView.UpdateHud(characterPresenter.status.hp);
                characterPresenter.itemModels.Remove(
                    characterPresenter.itemModels.FirstOrDefault(i => i.guid == item.guid));

                ItemPresenter itemPresenter = itemsListPresenter.Find(item.guid);
                if (itemPresenter != null && characterPresenter.SetItem(itemPresenter.status))
                {
                    itemsListPresenter.Delete(itemPresenter);
                }

                menuPresenter.itemMenuPresenter.ShowView(false);
            }
        }
    }
コード例 #2
0
ファイル: RogueMain.cs プロジェクト: abotkugyu/hod
    private void DefaultAction(CharacterPresenter characterPresenter)
    {
        InputAxis axis    = InputAxis.GetInputAxis();
        bool      isShift = Input.GetKey(KeyCode.LeftShift);
        bool      isZ     = Input.GetKey(KeyCode.Z);

        //攻撃
        if (Input.GetKeyDown(KeyCode.X) && characterPresenter.status.isAction == false && !characterPresenter.isMove)
        {
            characterPresenter.Attack(mapPresenter, characterListPresenter.characterListPresenter);
            characterListPresenter.Delete();
            return;
        }

        if (axis.F.x != 0 || axis.F.y != 0)
        {
            if (isZ && (axis.F.x == 0 || axis.F.y == 0))
            {
                return;
            }
            // 向き変更
            if (!characterPresenter.isMove)
            {
                characterPresenter.SetDirection(new Vector3(axis.I.x, 0, axis.I.y));
                // shiftが押されていたら方向転換だけ
                if (isShift)
                {
                    return;
                }
            }

            Vector2Int beforePosition = new Vector2Int((int)characterPresenter.status.position.x, (int)characterPresenter.status.position.z);
            Vector2Int afterPosition  = new Vector2Int(beforePosition.x + axis.I.x, beforePosition.y + axis.I.y);

            if (mapPresenter.IsCanMove(axis.I, beforePosition, characterPresenter.status.type))
            {
                if (!characterPresenter.isMove && characterPresenter.status.isAction == false)
                {
                    if (!isShift)
                    {
                        characterPresenter.Move(axis.F.x, axis.F.y);

                        //アイテムがあれば取得
                        if (mapPresenter.GetTileModel(afterPosition.x, afterPosition.y).itemGuid != 0)
                        {
                            ItemPresenter itemPresenter = itemsListPresenter.Find(mapPresenter.GetTileModel(afterPosition.x, afterPosition.y).itemGuid);

                            if (itemPresenter != null && characterPresenter.SetItem(itemPresenter.status))
                            {
                                itemsListPresenter.Delete(itemPresenter);

                                mapPresenter.SetItemModel(afterPosition.x, afterPosition.y, null);
                            }
                            else
                            {
                                Debug.Log("Cant Delete:null");
                            }
                        }

                        //階段あれば移動
                        if (mapPresenter.GetTileModel(afterPosition)
                            .tileType == TileModel.TileType.Stairs)
                        {
                            mapPresenter.Regenerate();
                        }

                        //移動元と移動先にキャラクター情報を設定
                        mapPresenter.SetUserModel(beforePosition, null);
                        mapPresenter.SetUserModel(afterPosition, characterPresenter.status);

                        characterPresenter.SetPosition(new Vector3(afterPosition.x, 0, afterPosition.y));
                    }
                }
            }
        }
    }