Exemplo n.º 1
0
    private void OnHarvestStart(SocketAsyncEventArgs args, byte[] bytes)
    {
        HarvestStart input = HarvestStart.Parser.ParseFrom(bytes);

        if (input.RoomId != RoomId)
        {
            return; // 不是自己房间的消息,略过
        }
        if (input.CellIndex == 0)
        {
            Debug.LogError("RoomLogic OnHarvestStart Error - Actor position is lost!");
        }
        HarvestStartReply output = new HarvestStartReply()
        {
            RoomId       = input.RoomId,
            OwnerId      = input.OwnerId,
            ActorId      = input.ActorId,
            CellIndex    = input.CellIndex,
            ResType      = input.ResType,
            ResRemain    = input.ResRemain,
            DurationTime = input.DurationTime,
            Ret          = true,
        };

        BroadcastMsg(ROOM_REPLY.HarvestStartReply, output.ToByteArray());
    }
Exemplo n.º 2
0
    public void Run()
    {
        var pi = CommandManager.Instance.CurrentExecuter;

        if (pi == null || !pi.CurrentActor)
        {
            string msg = $"没有选中任何部队!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            return;
        }

        var avMe = CommandManager.Instance.CurrentExecuter.CurrentActor;

        if (avMe == null)
        {
            return;
        }

        var   currentCell  = avMe.HexUnit.Location;
        var   resType      = currentCell.Res.ResType;
        int   resAmount    = currentCell.Res.GetAmount(resType);
        float durationTime = resAmount * 3.0f;

        if (resAmount <= 0)
        {
            string msg = $"本地没有任何资源,请去其他地方采集!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Warning);
            return;
        }

        // 看看行动点够不够
        if (!CmdAttack.IsActionPointGranted())
        {
            string msg = "行动点数不够, 本操作无法执行! ";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            Debug.Log("CmdHarvest Run Error - " + msg);
            return;
        }

        {
            HarvestStart output = new HarvestStart()
            {
                RoomId       = avMe.RoomId,
                OwnerId      = avMe.OwnerId,
                ActorId      = avMe.ActorId,
                CellIndex    = avMe.CellIndex,
                ResType      = (int)resType,
                ResRemain    = resAmount,
                DurationTime = durationTime,
            };
            GameRoomManager.Instance.SendMsg(ROOM.HarvestStart, output.ToByteArray());

            CmdAttack.SendAiStateHigh(avMe.OwnerId, avMe.ActorId, StateEnum.HARVEST, 0, 0, durationTime, durationTime);
            // 消耗行动点
            CmdAttack.TryCommand();
        }
    }