Esempio n. 1
0
    void Start()
    {
        ActionLogPresenter.CreateInstance();
        ItemData.Load();
        EnemyData.Load();
        PlayerData.Load();

        //map 生成
        mapPresenter.Generate();

        //enemy生成
        List <UserModel> enemies = EnemyData.GetRandoms(50);

        enemies.ForEach(enemy =>
        {
            Vector2Int _pos  = mapPresenter.GetPopPoint();
            UserModel _model = characterListPresenter.Generate(_pos, mapPresenter.GetTileModel(_pos.x, _pos.y).floorId, enemy);
            mapPresenter.SetUserModel(_pos, _model);
        });

        //player生成
        UserModel player = PlayerData.GetRandom();

        player.isOwn = true;

        Vector2Int position = mapPresenter.GetPopPoint();
        UserModel  model    = characterListPresenter.Generate(position, mapPresenter.GetTileModel(position.x, position.y).floorId, player);

        mapPresenter.SetUserModel(position, model);

        gameStatus = new GameStatusModel();

        //item 配置
        List <ItemModel> items = ItemData.GetRandoms(50);

        items.ForEach(item => itemsListPresenter.Generate(mapPresenter, item));

        //階段配置
        stairsListPresenter.Generate(mapPresenter);

        //dummy エネミー配置
        //enemiesListPresenter.DummyGenerate(mapPresenter, mapPresenter.CanSetObject(pos));

        //dummy 階段配置
        Vector2Int pos = mapPresenter.GetPopPoint();

        stairsListPresenter.DummyGenerate(mapPresenter, mapPresenter.CanSetObject(pos));

        CharacterPresenter characterPresenter = characterListPresenter.GetOwnCharacterPresenter();

        characterPresenter.characterView.Equip("");
        menuPresenter.itemMenuPresenter.Initialize(characterPresenter.itemModels);

        //Create Hud
        GameObject res = Resources.Load("Object/Hud") as GameObject;
        GameObject obj = UnityEngine.Object.Instantiate(res, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;

        hudPresenter = obj.GetComponent <HudPresenter>();
        hudPresenter.UpdateHud(characterPresenter.status);
    }
Esempio n. 2
0
    //攻撃処理
    public void Attack(MapPresenter m, Dictionary <int, CharacterPresenter> characterListPresenter)
    {
        Vector3 pos = status.position + status.direction;

        if (pos.x < 0 || pos.z < 0)
        {
            return;
        }

        var vector2Int = new Vector2Int((int)pos.x, (int)pos.z);

        if (m.GetTileModel(vector2Int).charaType == TileModel.CharaType.Player ||
            m.GetTileModel(vector2Int).charaType == TileModel.CharaType.Enemy)
        {
            CharacterPresenter characterPresenter =
                characterListPresenter
                .FirstOrDefault(presenter => presenter.Key == m.GetTileModel(vector2Int).guid).Value;

            int damage = CalcAction.CalcAttack(status, characterPresenter.status);

            Debug.Log("Attack Damage : " + damage);
            characterPresenter.CalcHp(damage);
            Debug.Log("After Hp : " + characterPresenter.status.hp);

            ActionLogPresenter.Instance.ShowView();
            ActionLogPresenter.Instance.AddLog(LogType.Attack, new string[] { status.name, characterPresenter.status.name, damage.ToString() });
            if (characterPresenter.status.hp <= 0)
            {
                characterPresenter.Death();
            }
        }
        SetIsAction(true);

        characterView.Attack();
    }
Esempio n. 3
0
    public void Generate(MapPresenter mapPresenter, ItemModel model)
    {
        // item object作成
        GameObject res = Resources.Load("Object/" + model.modelName.Replace('_', '/')) as GameObject;
        Vector2Int pos = mapPresenter.GetPopPoint();
        GameObject obj = Object.Instantiate(res, new Vector3(pos.x, 0, pos.y), Quaternion.identity) as GameObject;

        obj.name             = "Item;" + serialGuid;
        obj.layer            = 9;
        obj.transform.parent = transform;

        // item model作成
        ItemPresenter itemPresenter = obj.AddComponent <ItemPresenter>();

        itemPresenter.itemView       = obj.AddComponent <ItemView>();
        itemPresenter.itemView.model = obj;

        itemPresenter.Initialize(model, serialGuid);
        itemPresenter.SetMapData(
            mapPresenter.GetTileModel(pos.x, pos.y).floorId,
            new Vector3(pos.x, 0, pos.y),
            new Vector3(0, 0, -1)
            );

        itemListPresenter[serialGuid] = itemPresenter;
        itemListObject[serialGuid]    = obj;
        serialGuid++;

        mapPresenter.SetItemModel(pos.x, pos.y, itemPresenter.status);
    }
Esempio n. 4
0
    public void Generate(MapPresenter mapPresenter)
    {
        for (int x = 0; x < num; x++)
        {
            GameObject obj = Object.Instantiate(Resources.Load("Object/Map/Stairs")) as GameObject;
            Vector2Int pos = mapPresenter.GetPopPoint();

            obj.transform.position = new Vector3(pos.x, 0, pos.y);
            obj.layer = 9;

            stairsList.Add(obj);
            //mapに配置
            mapPresenter.GetTileModel(pos.x, pos.y).tileType = TileModel.TileType.Stairs;
        }
    }
Esempio n. 5
0
    //全ての敵に行動させる
    public void AllAction(MapPresenter mapPresenter)
    {
        // Dictionary<int, EnemyPresenter> plauerInSideFloorEnemy = enemyListPresenter.Select(enemy =>
        // enemy.Value.status.floorId == 0).ToDictionary(enemy => );

        Dictionary <int, CharacterPresenter> plauerInSideFloorEnemy  = new Dictionary <int, CharacterPresenter>();
        Dictionary <int, CharacterPresenter> plauerOutSideFloorEnemy = new Dictionary <int, CharacterPresenter>();

        /// TODO全プレイヤーで検索する
        CharacterPresenter player = characterListPresenter.FirstOrDefault(presenter => presenter.Value.status.type == TileModel.CharaType.Player).Value;


        //プレイヤーと同じフロアにいるかで分ける
        foreach (KeyValuePair <int, CharacterPresenter> enemy in characterListPresenter.Where(presenter => presenter.Value.status.type == TileModel.CharaType.Enemy))
        {
            enemy.Value.beforeStatus = enemy.Value.status;
            if (enemy.Value.status.floorId == player.status.floorId)
            {
                plauerInSideFloorEnemy.Add(enemy.Key, enemy.Value);
            }
            else
            {
                plauerOutSideFloorEnemy.Add(enemy.Key, enemy.Value);
            }
        }

        // プレイヤーに近い順に並べて行動させるようにソートする。
        foreach (KeyValuePair <int, CharacterPresenter> enemy in plauerInSideFloorEnemy)
        {
            //GetFirstPositionAStar(enemy.Value.status.position, playerPresenter.status.position, mapPresenter);
        }

        var around1   = new DirectionUtil().GetAroundDirection(1);
        var around100 = new DirectionUtil().GetAroundDirection(100);

        foreach (KeyValuePair <int, CharacterPresenter> enemy in characterListPresenter.Where(presenter => presenter.Value.status.type == TileModel.CharaType.Enemy))
        {
            CharacterPresenter characterPresenter = enemy.Value;

            // 周りにプレイヤーがいれば攻撃
            var searchDirection1  = around1.Select(i => i + characterPresenter.status.position.GetVector2Int());
            var hitEnemyDirection = searchDirection1.Where(i => mapPresenter.SearchCharaType(i, TileModel.CharaType.Player));

            if (hitEnemyDirection.Any())
            {
                Vector2Int direction = hitEnemyDirection.First() - characterPresenter.status.position.GetVector2Int();
                characterPresenter.SetDirection(direction.GetVector2Int());
                characterPresenter.Attack(mapPresenter, characterListPresenter);
                characterPresenter.SetIsAction(true);
                continue;
            }

            // 攻撃できなければランダムアクション
            int actionType = characterPresenter.GetAction();
            if (actionType == 1)
            {
                InputAxis axis = InputAxis.GetRandomAxis();
                //キャッシュに残るもので移動できるか、移動できなければ再計算
                if (characterPresenter.cacheNextDestination.Count > 0 && mapPresenter.IsCanMove(characterPresenter.cacheNextDestination.First() - characterPresenter.status.position.GetVector2Int(),
                                                                                                characterPresenter.status.position.GetVector2Int(), characterPresenter.status.type))
                {
                    axis = new InputAxis(characterPresenter.cacheNextDestination.First() -
                                         characterPresenter.status.position.GetVector2Int());
                    characterPresenter.cacheNextDestination.RemoveAt(0);
                }
                else
                {
                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                    sw.Start();
                    //通路を検索
                    var to = mapPresenter.GetFloorModel(characterPresenter.status.floorId).innerPath.GetRandom();
                    if (to != Vector2Int.zero && to != characterPresenter.status.position.GetVector2Int())
                    {
                        var wayList = GetDestinationWayList(characterPresenter.status.position.GetVector2Int(), to,
                                                            mapPresenter, characterPresenter);
                        if (wayList.Length > 0)
                        {
                            axis = new InputAxis(wayList.First() - characterPresenter.status.position.GetVector2Int());
                            characterPresenter.cacheNextDestination = wayList.ToList();
                        }
                    }
                    sw.Stop();
                    Debug.Log(characterPresenter.status.guid + ",from:" + characterPresenter.status.position.GetVector2Int() + ",to:" + to + ",time:" + sw.ElapsedMilliseconds);
                }


                if (axis.I == new Vector2Int(0, 0))
                {
                    //移動先がなければ行動済みにする。
                    characterPresenter.SetIsAction(true);
                    continue;
                }

                if (!mapPresenter.IsCanMove(axis.I, characterPresenter.status.position.GetVector2Int(), characterPresenter.status.type))
                {
                    // TODO 移動先に邪魔なものがあれば縦か横移動をする。
                    characterPresenter.SetIsAction(true);
                    continue;
                }

                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);

                characterPresenter.Move(axis.F.x, axis.F.y);

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

                characterPresenter.SetMapData(
                    mapPresenter.GetTileModel(afterPosition).floorId,
                    new Vector3(afterPosition.x, 0, afterPosition.y),
                    new Vector3(axis.I.x, 0, axis.I.y)
                    );
            }
            else
            {
                //GetNearCharacterPosition(GameConfig.SearchType.Around8, TileModel.CharaType.Player, mapPresenter.map);
                characterPresenter.SetIsAction(true);
            }
        }
    }