예제 #1
0
    HexUnit CreateHero(HexCell cell)
    {
        HexUnit createHero = Instantiate <TestHero>(hero);

        grid.AddUnit(
            createHero, cell, Random.Range(0f, 360f)
            );
        return(createHero);
    }
예제 #2
0
    void CreateUnit()
    {
        HexCell cell = GetCellUnderCursor();

        Debug.Log(cell.coordinates + "X:" + cell.coordinates.X + "Z:" + cell.coordinates.Z);
        if (cell && !cell.Unit)
        {
            hexGrid.AddUnit(
                Instantiate(HexUnit.unitPrefab), cell, Random.Range(0f, 360f)
                );
        }
    }
예제 #3
0
    public static void Load(BinaryReader reader, HexGrid grid)
    {
        HexCoordinates coordinates = HexCoordinates.Load(reader);
        float          orientation = reader.ReadSingle();

        grid.AddUnit(Instantiate(unitPrefab), grid.GetCell(coordinates), orientation);
    }
예제 #4
0
    public static void Load(BinaryReader reader, HexGrid grid)
    {
        HexCoordinates c   = HexCoordinates.Load(reader);
        float          rot = reader.ReadSingle();

        grid.AddUnit(Instantiate(unitPrefab), grid.GetCell(c), rot);
    }
예제 #5
0
 public void CreateUnit(HexCell cell)
 {
     if (cell && cell.HexUnit == null)
     {
         HexUnit unit = Instantiate(HexUnit.UnitPrefab);
         HexGrid.AddUnit(unit, cell, UnityEngine.Random.Range(0f, 360f));
     }
 }
예제 #6
0
    //Creates an AI controlled merchant player with a ship and adds it to controllers
    private void CreateMerchantPlayer(Route route)
    {
        MerchantShip newShip = Instantiate(merchantShip);

        newShip.transform.SetParent(shipParent);
        newShip.Setup(route);

        //Delegates
        newShip.OnShipBoarded   += worldUIView.OpenBoardingView;
        newShip.OnShipInspected += worldUIView.OpenInspectView;

        hexGrid.AddUnit(newShip, route.GetSpawnableLocation(), HexDirectionExtension.ReturnRandomDirection(), false);

        Player newMerchantPlayer = new Player(newShip, null, false);

        MapTurnSystem.instance.AddPlayerToTurnOrder(newMerchantPlayer);
    }
예제 #7
0
    void CreateUnit()
    {
        HexCell cell = GetCellUnderCursor();

        if (cell && !cell.Unit)
        {
            hexGrid.AddUnit(Instantiate(HexUnit.unitPrefab), cell, Random.Range(0f, 360f));
        }
    }
예제 #8
0
    private void CreateUnit()
    {
        HexCell cell = GetCellUnderCursor();

        if (cell && !cell.Unit)
        {
            hexGrid.AddUnit(cell, Random.Range(0, 360));
        }
    }
예제 #9
0
    void CreateUnit(int currentPlayer)
    {
        HexCell cell = GetCellUnderCursor();

        if (cell && !cell.Unit)
        {
            hexGrid.AddUnit(Instantiate(HexUnit.unitPrefabs[currentPlayer]), cell, Random.Range(0f, 360f), currentPlayer);
        }
    }
예제 #10
0
    private void CreateUnit()
    {
        var cell = GetCellUnderCursor();

        if (cell && !cell.Unit)
        {
            hexGrid.AddUnit(Instantiate(Unit.unitPrefab), cell, Random.Range(0, 360));
        }
    }
예제 #11
0
    void CreateUnit()
    {
        HexCell cell = GetCellUnderCursor();

        if (cell && cell.units.Count < 6)
        {
            hexGrid.AddUnit(Instantiate(unitPrefab), cell, Random.Range(0f, 360f));
        }
    }
예제 #12
0
    public static void Load(BinaryReader reader, HexGrid grid, bool ownerCompatibility = false)
    {
        HexCoordinates coordinates = HexCoordinates.Load(reader);
        float          orientation = reader.ReadSingle();
        int            owner       = ownerCompatibility ? reader.ReadInt32() : 0;

        grid.AddUnit(
            Instantiate(unitPrefabs[owner]), grid.GetCell(coordinates), orientation, owner
            );
    }
    void CreateUnit()
    {
        HexCell cell = GetCellUnderCursor();

        if (cell && !cell.CharacterManager)
        {
            hexGrid.AddUnit(
                Instantiate(CharacterManager.unitPrefab), cell, Random.Range(0f, 360f)
                );
        }
    }
예제 #14
0
    public HexUnit CreateAgent(AgentConfig agentConfig, HexCell cell, Player player)
    {
        HexUnit hexUnit = Instantiate(agentPrefab).GetComponent <HexUnit>();
        Agent   agent   = hexUnit.GetComponent <Agent>();

        agent.SetAgentConfig(agentConfig);
        hexGrid.AddUnit(hexUnit);
        hexUnit.Grid        = hexGrid;
        hexUnit.Location    = cell;
        hexUnit.Orientation = Random.Range(0f, 360f);
        hexUnit.HexUnitType = HexUnit.UnitType.AGENT;

        if (player.IsHuman)
        {
            hexUnit.Controllable = true;
        }

        hexUnit.HexUnitType = HexUnit.UnitType.AGENT;
        player.AddAgent(agent);
        return(hexUnit);
    }
예제 #15
0
    void CreateUnit()
    {
        HexCell cell = GetCellUnderCursor();

        Debug.Log(cell.coordinates.ToString());
        if (cell && !cell.Unit)
        {
            hexGrid.AddUnit(
                Instantiate(selectedUnit), cell, Random.Range(0f, 360f)
                );
        }
    }
    void AddUnits()
    {
        if (isServer)
        {
            gameUI.myUnit    = myUnit = serverUnit;
            gameUI.otherUnit = otherUnit = clientUnit;
        }
        else
        {
            serverStart = grid.GetCell(StartInfo.ServerIndex);
            clientStart = grid.GetCell(StartInfo.ClientIndex);

            gameUI.myUnit    = myUnit = clientUnit;
            gameUI.otherUnit = otherUnit = serverUnit;
        }

        Log.Dev(GetType(), "server starts at " + serverStart.coordinates.ToString() + " client starts at " + clientStart.coordinates.ToString());

        grid.AddUnit(serverUnit, serverStart);
        grid.AddUnit(clientUnit, clientStart);
    }
예제 #17
0
    public void Setup(HexGrid hexGrid, SetupData setupData, WorldController worldController)
    {
        CreateWater(setupData);
        CreateMap(hexGrid, setupData, worldController);

        //Add temporary ship to do pathfinding and finding harbors
        MerchantShip setupShip = Instantiate(merchantShip.gameObject).GetComponent <MerchantShip>();

        hexGrid.AddUnit(setupShip, worldController.HarborCells[0], false);

        for (int i = 0; i < worldController.MerchantRoutes.Length; i++)
        {
            int tries = 0;

            //Find harbors for route
            HexCell startHarbor = Utility.ReturnRandomElementWithCondition(worldController.HarborCells, (h) => h.Unit != null);
            setupShip.Location = startHarbor;

            int            numberOfHarbors = Random.Range(setupData.routeMinStops, setupData.routeMaxStops + 1);
            List <HexCell> harbors         = new List <HexCell>(numberOfHarbors);
            harbors.Add(startHarbor);
            for (int j = 1; j < numberOfHarbors; j++)
            {
                HexCell foundHarbor = worldController.GetRandomHarborWithinRange(setupShip, setupData.routeMinLength, setupData.routeMaxLength);
                if (foundHarbor == null)
                {
                    break;
                }
                harbors.Add(foundHarbor);
            }

            if (harbors.Count < 2)
            {
                Debug.Log("Did not find enough harbors to add to route, trying with a differnt start harbor");
                i--;
                tries++;
                if (tries < setupData.routes * 2)
                {
                    break;
                }
                else
                {
                    continue;
                }
            }
            //Create route between harbors
            worldController.MerchantRoutes[i] = new Route(harbors.ToArray());
        }
        //Remove Temporary Ship
        hexGrid.RemoveUnit(setupShip);
    }
예제 #18
0
 public void CreateScout()
 {
     if ((gameManager.GetRessourceCount(ResourceType.Nectar) >= scoutNectarCost) && (gameManager.GetRessourceCount(ResourceType.Pollen) >= scoutPollenCost))
     {
         gameManager.RemovePlayerRessources(ResourceType.Nectar, scoutNectarCost);
         gameManager.RemovePlayerRessources(ResourceType.Pollen, scoutPollenCost);
         Debug.Log("Let's explore this hood!");
         HexCell cell = hexGrid.GetCell(new Vector3(13, -30, 17));
         if (cell && !cell.Unit)
         {
             hexGrid.AddUnit(Instantiate(HexUnit.unitPrefab), cell, Random.Range(0f, 360f));
         }
     }
 }
예제 #19
0
파일: HexMapEditor.cs 프로젝트: zhl-dru/Hex
    /// <summary>
    /// 添加单位
    /// </summary>
    void CreateUnit()
    {
        HexCell cell = GetCellUnderCursor();

        if (cell && !cell.Unit)
        {
            //HexUnit unit = Instantiate(unitPrefab);
            //Instantiate(unitPrefab);
            //unit.transform.SetParent(hexGrid.transform, false);
            //unit.Location = cell;
            //unit.Orientation = Random.Range(0f, 360f);
            hexGrid.AddUnit(Instantiate(HexUnit.unitPrefab), cell, Random.Range(0f, 360f));
        }
    }
예제 #20
0
    // Unit
    void CreateUnit()
    {
        HexCell hexCell = GetCellUnderCursor();

        if (hexCell && !hexCell.Unit)
        {
            /*
             * HexUnit unit = Instantiate(unitPrefab);
             * unit.transform.SetParent(hexGrid.transform, false);
             * unit.Location = hexCell;
             * unit.Rotation = Random.Range(0f, 360f);
             */

            hexGrid.AddUnit(Instantiate(HexUnit.unitPrefab), hexCell, Random.Range(0f, 360f));
        }
    }
예제 #21
0
    public void CreateUnit(int pPrefabIndex, CharacterClasses pclasse, HexCell cell)
    {
        if (pPrefabIndex < specie.unitsPrefabs.Count)
        {
            GameObject toInstanciate = specie.unitsPrefabs[pPrefabIndex];
            GameObject go            = Instantiate(toInstanciate);
            Unit       unit          = go.GetComponent <Unit>();

            unit.classe = pclasse;
            unit.Init();
            unit.SetTeam(this);

            grid.AddUnit(unit, cell, Random.Range(0f, 360f));

            // Add instiated unit to team
            units.Add(unit);
        }
    }
예제 #22
0
    //Creates a player from a prefab and spawns a ship, starting characters and adds them to controllers
    private void CreateHumanPlayer()
    {
        Ship newShip = Instantiate(playerStarterShip);

        newShip.transform.SetParent(shipTransform);

        worldGrid.AddUnit(newShip, worldController.PlayerSpawnPosition, HexDirectionExtension.ReturnRandomDirection(), true);

        combatSystem.managementMap = playerStartingGridMap;

        Player newPlayer = new Player(newShip, true, playerCrewSimulation);

        MapTurnSystem.instance.AddPlayerToFirstPositionInTurnOrder(newPlayer);
        HexGridController.player = newPlayer;
        newPlayer.PlayerData.NextBountyChange = setupData.difficultySettings.bountyChanges;
        for (int i = 0; i < startingCharacters.Length; i++)
        {
            HexGridController.SpawnCharacterForPlayerCrew(startingCharacters[i]);
        }
        OnPlayerCreated?.Invoke(newPlayer);
    }
예제 #23
0
    void CreateUnit()
    {
        HexCell cell = GetCellUnderCursor();

        if (cell && !cell.Unit)
        {
            HexUnit prefab = HexUnit.unitPrefab;

            if (unitDropdown.captionText.text == "Joffy")
            {
                prefab.unitName   = prefab.name = "Joffy";
                prefab.hp         = 20;
                prefab.initiative = 10;
                prefab.atk        = 4;
                prefab.movement   = 3;
            }
            if (unitDropdown.captionText.text == "Peppsen")
            {
                prefab.unitName   = prefab.name = "Peppsen";
                prefab.hp         = 12;
                prefab.initiative = 12;
                prefab.atk        = 6;
                prefab.movement   = 4;
            }
            if (unitDropdown.captionText.text == "Jesus")
            {
                prefab.hp         = 14;
                prefab.unitName   = prefab.name = "Jesus";
                prefab.initiative = 8;
                prefab.atk        = 2;
                prefab.movement   = 5;
            }

            hexGrid.AddUnit(Instantiate(prefab), cell, Random.Range(0f, 360f));
        }
    }
예제 #24
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="roomId">房间id</param>
    /// <param name="ownerId">所属玩家id</param>
    /// <param name="actorId">自己的id</param>
    /// <param name="posX"></param>
    /// <param name="posZ"></param>
    /// <param name="orientation"></param>
    /// <param name="unitName"></param>
    /// <param name="cellIndex">该单位在地形块HexCell中的Index,因为根据PosX,PosZ可能得不到正确的cell,只能用这个数据确保正确</param>
    /// <param name="actorInfoId">兵种ID,在actor_info表中的id</param>
    /// <param name="name"></param>
    /// <param name="hp"></param>
    /// <param name="attackPower"></param>
    /// <param name="defencePower"></param>
    /// <param name="speed"></param>
    /// <param name="filedOfVision"></param>
    /// <param name="shootingRange"></param>
    /// <param name="attackDuration"></param>
    /// <param name="attackInterval"></param>
    /// <param name="ammoBase"></param>
    /// <param name="ammoBaseMax"></param>
    /// <returns></returns>
    public ActorVisualizer CreateUnit(long roomId, long ownerId, long actorId, int posX, int posZ, float orientation,
                                      string unitName, int cellIndex, int actorInfoId,
                                      string name, int hp, int hpMax, float attackPower, float defencePower, float speed, float filedOfVision, float shootingRange,
                                      float attackDuration, float attackInterval, int ammoBase, int ammoBaseMax)
    {
        HexCell cell = GetCell(cellIndex);

        if (!cell)
        {
            GameRoomManager.Instance.Log($"HexmapHelper CreateUnit :创建Actor失败!格子越界 - <{posX},{posZ}> - {unitName}");
            return(null);
        }

        if (cellIndex == 0)
        {
            Debug.LogError("HexmapHelper CreateUnit Error - CellIndex is lost!!!");
            return(null);
        }

        if (cell.Unit)
        {
            HexCell newCell = null;
            for (HexDirection d = HexDirection.NE; d <= HexDirection.NW; d++)
            {
                HexCell neighbor = cell.GetNeighbor(d);
                if (neighbor && !neighbor.Unit)
                {
                    newCell = neighbor;
                    break;
                }
            }

            if (newCell)
            {
                GameRoomManager.Instance.Log($"HexmapHelper :创建Actor失败!物体位置重合了,重新放置! - 原坐标:<{posX},{posZ}> - 新坐标:<{newCell.coordinates.X},{newCell.coordinates.Z}> - {unitName}");
                cell = newCell;
            }
            else
            {
                GameRoomManager.Instance.Log($"HexmapHelper :创建Actor失败!原来这个格子没有物体,现在有了物体, 附近也没有空地! - <{posX},{posZ}> - {unitName}");
                return(null);
            }
        }

        // 区分颜色
        string newUnitName = unitName;

        if (ownerId != GameRoomManager.Instance.CurrentPlayer.TokenId)
        { // 如果不是自己,蓝色就换成红色(绿色换成黄色)
            if (unitName.IndexOf("BLUE") > 0)
            {
                newUnitName = unitName.Replace("BLUE", "RED");
            }
            else if (unitName.IndexOf("GREEN") > 0)
            {
                newUnitName = unitName.Replace("GREEN", "YELLOW");
            }
        }

        string unitPathName = $"Arts/BeffioPrefabs/Soldiers/{newUnitName}";
        var    go           = Resources.Load <HexUnit>(unitPathName);

        if (go != null)
        {
            HexUnit hu = Instantiate(go);
            if (hu != null)
            {
                hexGrid.AddUnit(hu, cell, orientation);
                var av = hu.GetComponent <ActorVisualizer>();
                if (av != null)
                {
                    av.RoomId      = roomId;
                    av.OwnerId     = ownerId;
                    av.ActorId     = actorId;
                    av.PosX        = posX;
                    av.PosZ        = posZ;
                    av.Orientation = orientation;
                    av.Species     = unitName;
                    av.CellIndex   = cellIndex;
                    av.ActorInfoId = actorInfoId;

                    av.Name          = name;
                    av.Hp            = hp;
                    av.HpMax         = hpMax;
                    av.AttackPower   = attackPower;
                    av.DefencePower  = defencePower;
                    av.Speed         = speed;
                    av.FieldOfVision = filedOfVision;
                    av.ShootingRange = shootingRange;

                    av.AttackDuration = attackDuration;
                    av.AttackInterval = attackInterval;
                    av.AmmoBase       = ammoBase;
                    av.AmmoBaseMax    = ammoBaseMax;
                }

                // 关闭预制件上没用的东西,看以后这东西能否用得上,如果没用,就完全干掉
                if (hu.GetComponentInChildren <ThirdPersonUserControl>())
                {
                    hu.GetComponentInChildren <ThirdPersonUserControl>().enabled = false;
                }
                if (hu.GetComponentInChildren <ThirdPersonCharacter>())
                {
                    hu.GetComponentInChildren <ThirdPersonCharacter>().enabled = false;
                }
                if (hu.GetComponentInChildren <CapsuleCollider>())
                {
                    hu.GetComponentInChildren <CapsuleCollider>().enabled = false;
                }
                EnableFollowCamera(av, false);

                if (!GameRoomManager.Instance.RoomLogic.ActorManager.AllActors.ContainsKey(actorId))
                {
                    ActorBehaviour ab = new ActorBehaviour()
                    {
                        RoomId      = roomId,
                        OwnerId     = ownerId,
                        ActorId     = actorId,
                        PosX        = posX,
                        PosZ        = posZ,
                        Orientation = orientation,
                        Species     = unitName,
                        CellIndex   = cellIndex,
                        ActorInfoId = actorInfoId,

                        Name          = name,
                        Hp            = hp,
                        HpMax         = hpMax,
                        AttackPower   = attackPower,
                        DefencePower  = defencePower,
                        Speed         = speed,
                        FieldOfVision = filedOfVision,
                        ShootingRange = shootingRange,

                        AttackDuration = attackDuration,
                        AttackInterval = attackInterval,
                        AmmoBase       = ammoBase,
                        AmmoBaseMax    = ammoBaseMax,
                    };
                    GameRoomManager.Instance.RoomLogic.ActorManager.AddActor(ab, hu);
                }
                GameRoomManager.Instance.Log($"MSG: CreateATroopReply - 创建了一个Actor - {unitName}");
                return(av);
            }
        }

        return(null);
    }