Exemple #1
0
        public void DisplayUsingStunt(SceneObject sceneObject, Stunt stunt)
        {
            if (!_isUsing)
            {
                return;
            }
            var message = new BattleSceneDisplayUsingStuntMessage();

            message.obj   = StreamableFactory.CreateBattleSceneObject(sceneObject);
            message.stunt = StreamableFactory.CreateCharacterPropertyDescription(stunt);
            _connection.SendMessage(message);
        }
Exemple #2
0
        public void DisplayUsingAspect(SceneObject userSceneObject, SceneObject ownerSceneObject, Aspect aspect)
        {
            if (!_isUsing || !BattleSceneContainer.Instance.IsChecking)
            {
                return;
            }
            var message = new BattleSceneCheckerDisplayUsingAspectMessage();

            message.userObj        = StreamableFactory.CreateBattleSceneObject(userSceneObject);
            message.aspectOwnerObj = StreamableFactory.CreateBattleSceneObject(ownerSceneObject);
            message.aspect         = StreamableFactory.CreateCharacterPropertyDescription(aspect);
            _connection.SendMessage(message);
        }
        private Message GetDirectResistStunts(SkillType initiativeSkillType, Character passive, CharacterAction action)
        {
            var          message     = new DirectResistStuntsListMessage();
            List <Stunt> resistables = new List <Stunt>();

            if (passive.Stunts != null)
            {
                foreach (var stunt in passive.Stunts)
                {
                    if (stunt.CanResistSkillWithoutDMCheck(initiativeSkillType, action))
                    {
                        resistables.Add(stunt);
                    }
                }
            }
            message.characterID = passive.ID;
            message.stunts      = new CharacterPropertyDescription[resistables.Count];
            for (int i = 0; i < resistables.Count; ++i)
            {
                message.stunts[i] = StreamableFactory.CreateCharacterPropertyDescription(resistables[i]);
            }
            return(message);
        }
Exemple #4
0
        public Message MakeResponse(Message request)
        {
            try {
                if (!_isUsing)
                {
                    return(null);
                }
                var container = BattleSceneContainer.Instance;
                switch (request.MessageType)
                {
                case BattleSceneGetGridObjectDataMessage.MESSAGE_TYPE: {
                    var reqMsg     = (BattleSceneGetGridObjectDataMessage)request;
                    var resp       = new BattleSceneGridObjectDataMessage();
                    var gridObject = BattleSceneContainer.Instance.FindObject(reqMsg.objID) as GridObject;
                    if (gridObject == null)
                    {
                        return(null);
                    }
                    resp.objData = StreamableFactory.CreateBattleSceneGridObjData(gridObject);
                    return(resp);
                }

                case BattleSceneGetLadderObjectDataMessage.MESSAGE_TYPE: {
                    var reqMsg       = (BattleSceneGetLadderObjectDataMessage)request;
                    var resp         = new BattleSceneLadderObjectDataMessage();
                    var ladderObject = BattleSceneContainer.Instance.FindObject(reqMsg.objID) as LadderObject;
                    if (ladderObject == null)
                    {
                        return(null);
                    }
                    resp.objData = StreamableFactory.CreateBattleSceneLadderObjData(ladderObject);
                    return(resp);
                }

                case BattleSceneGetMovePathInfoMessage.MESSAGE_TYPE: {
                    if (!_canOperate || container.CurrentActable.CharacterRef.Controller != _owner)
                    {
                        break;
                    }
                    var list = container.CurrentActable.GetReachablePlaceList();
                    var resp = CreateMovePathInfoMessage(list);
                    return(resp);
                }

                case BattleSceneGetCanExtraMoveMessage.MESSAGE_TYPE: {
                    if (!_canOperate || container.CurrentActable.CharacterRef.Controller != _owner)
                    {
                        break;
                    }
                    var resp = new BattleSceneCanTakeExtraMoveMessage();
                    resp.result = container.CurrentActable.CanTakeExtraMove();
                    return(resp);
                }

                case BattleSceneGetInitiativeUsableSkillOrStuntListMessage.MESSAGE_TYPE: {
                    if (!_canOperate || container.CurrentActable.CharacterRef.Controller != _owner)
                    {
                        break;
                    }
                    var reqMsg = (BattleSceneGetInitiativeUsableSkillOrStuntListMessage)request;
                    if (reqMsg.stunt)
                    {
                        var resp      = new BattleSceneObjectUsableStuntListMessage();
                        var candoList = new List <Stunt>();
                        if (container.CurrentActable.CharacterRef.Stunts != null)
                        {
                            foreach (var stunt in container.CurrentActable.CharacterRef.Stunts)
                            {
                                if (container.CurrentActable.CanUseStuntInAction(stunt, reqMsg.action) &&
                                    container.CurrentActable.IsActionPointEnough(stunt.BattleMapProperty))
                                {
                                    candoList.Add(stunt);
                                }
                            }
                        }
                        resp.stunts = new CharacterPropertyDescription[candoList.Count];
                        for (int i = 0; i < candoList.Count; ++i)
                        {
                            resp.stunts[i] = StreamableFactory.CreateCharacterPropertyDescription(candoList[i]);
                        }
                        return(resp);
                    }
                    else
                    {
                        var resp      = new BattleSceneObjectUsableSkillListMessage();
                        var candoList = new List <SkillType>();
                        foreach (var skillType in SkillType.SkillTypes)
                        {
                            var battleMapProperty = container.CurrentActable.CharacterRef.GetSkill(skillType.Value).BattleMapProperty;
                            if (container.CurrentActable.CanUseSkillInAction(skillType.Value, reqMsg.action) &&
                                container.CurrentActable.IsActionPointEnough(battleMapProperty))
                            {
                                candoList.Add(skillType.Value);
                            }
                        }
                        resp.skillTypes = new SkillTypeDescription[candoList.Count];
                        for (int i = 0; i < candoList.Count; ++i)
                        {
                            resp.skillTypes[i] = StreamableFactory.CreateSkillTypeDescription(candoList[i]);
                        }
                        return(resp);
                    }
                }

                case BattleSceneGetInitiativeUsableSkillOrStuntListOnInteractMessage.MESSAGE_TYPE: {
                    if (!_canOperate || container.CurrentActable.CharacterRef.Controller != _owner)
                    {
                        break;
                    }
                    var reqMsg = (BattleSceneGetInitiativeUsableSkillOrStuntListOnInteractMessage)request;
                    if (reqMsg.stunt)
                    {
                        var resp      = new BattleSceneObjectUsableStuntListOnInteractMessage();
                        var candoList = new List <Stunt>();
                        if (container.CurrentActable.CharacterRef.Stunts != null)
                        {
                            foreach (var stunt in container.CurrentActable.CharacterRef.Stunts)
                            {
                                if (container.CurrentActable.CanUseStuntOnInteract(stunt) &&
                                    container.CurrentActable.IsActionPointEnough(stunt.BattleMapProperty))
                                {
                                    candoList.Add(stunt);
                                }
                            }
                        }
                        resp.stunts = new CharacterPropertyDescription[candoList.Count];
                        for (int i = 0; i < candoList.Count; ++i)
                        {
                            resp.stunts[i] = StreamableFactory.CreateCharacterPropertyDescription(candoList[i]);
                        }
                        return(resp);
                    }
                    else
                    {
                        var resp      = new BattleSceneObjectUsableSkillListOnInteractMessage();
                        var candoList = new List <SkillType>();
                        foreach (var skillType in SkillType.SkillTypes)
                        {
                            var battleMapProperty = container.CurrentActable.CharacterRef.GetSkill(skillType.Value).BattleMapProperty;
                            if (container.CurrentActable.CanUseSkillOnInteract(skillType.Value) &&
                                container.CurrentActable.IsActionPointEnough(battleMapProperty))
                            {
                                candoList.Add(skillType.Value);
                            }
                        }
                        resp.skillTypes = new SkillTypeDescription[candoList.Count];
                        for (int i = 0; i < candoList.Count; ++i)
                        {
                            resp.skillTypes[i] = StreamableFactory.CreateSkillTypeDescription(candoList[i]);
                        }
                        return(resp);
                    }
                }

                case BattleSceneGetActionAffectableAreasMessage.MESSAGE_TYPE: {
                    if (!_canOperate || container.CurrentActable.CharacterRef.Controller != _owner)
                    {
                        break;
                    }
                    var reqMsg = (BattleSceneGetActionAffectableAreasMessage)request;
                    var resp   = new BattleSceneActionAffectableAreasMessage();
                    Dictionary <GridPos, List <GridPos> > areas;
                    if (reqMsg.isStunt)
                    {
                        var stunt = container.CurrentActable.CharacterRef.FindStuntByID(reqMsg.skillTypeOrStuntID);
                        areas = container.CurrentActable.GetStuntAffectableAreas(stunt);
                    }
                    else
                    {
                        var skillType = SkillType.SkillTypes[reqMsg.skillTypeOrStuntID];
                        areas = container.CurrentActable.GetSkillAffectableAreas(skillType);
                    }
                    resp.centers = new GridPos[areas.Count];
                    resp.areas   = new GridPos[areas.Count][];
                    int i = 0;
                    foreach (var area in areas)
                    {
                        resp.centers[i] = new GridPos()
                        {
                            row = area.Key.row, col = area.Key.col, highland = area.Key.highland
                        };
                        var gridList  = area.Value;
                        int gridCount = area.Value.Count;
                        resp.areas[i] = new GridPos[gridCount];
                        for (int j = 0; j < gridCount; ++j)
                        {
                            resp.areas[i][j] = new GridPos()
                            {
                                row = gridList[j].row, col = gridList[j].col, highland = gridList[j].highland
                            };
                        }
                        ++i;
                    }
                    return(resp);
                }

                case BattleSceneGetActionTargetCountMessage.MESSAGE_TYPE: {
                    if (!_canOperate || container.CurrentActable.CharacterRef.Controller != _owner)
                    {
                        break;
                    }
                    var reqMsg = (BattleSceneGetActionTargetCountMessage)request;
                    var resp   = new BattleSceneActionTargetCountMessage();
                    if (reqMsg.isStunt)
                    {
                        var stunt = container.CurrentActable.CharacterRef.FindStuntByID(reqMsg.skillTypeOrStuntID);
                        resp.count = stunt.BattleMapProperty.targetMaxCount;
                    }
                    else
                    {
                        var skillType = SkillType.SkillTypes[reqMsg.skillTypeOrStuntID];
                        resp.count = container.CurrentActable.CharacterRef.GetSkill(skillType).BattleMapProperty.targetMaxCount;
                    }
                    return(resp);
                }

                case GetStuntTargetSelectableMessage.MESSAGE_TYPE: {
                    if (!_canOperate || container.CurrentActable.CharacterRef.Controller != _owner)
                    {
                        break;
                    }
                    var reqMsg = (GetStuntTargetSelectableMessage)request;
                    var target = container.FindObject(reqMsg.targetID);
                    var stunt  = container.CurrentActable.CharacterRef.FindStuntByID(reqMsg.stuntID);
                    if (target != null && stunt != null)
                    {
                        var resp = new StuntTargetSelectableMessage();
                        resp.result = container.CurrentActable.CanUseStuntOnTarget(target, stunt, reqMsg.isInteract, reqMsg.action);
                        return(resp);
                    }
                    else
                    {
                        break;
                    }
                }

                case BattleSceneGetPassiveUsableSkillOrStuntListMessage.MESSAGE_TYPE: {
                    if (!container.IsChecking || container.CurrentPassive.CharacterRef.Controller != _owner)
                    {
                        break;
                    }
                    var reqMsg = (BattleSceneGetPassiveUsableSkillOrStuntListMessage)request;
                    if (reqMsg.stunt)
                    {
                        var resp      = new BattleSceneObjectUsableStuntListMessage();
                        var candoList = new List <Stunt>();
                        if (container.CurrentPassive.CharacterRef.Stunts != null)
                        {
                            foreach (var stunt in container.CurrentPassive.CharacterRef.Stunts)
                            {
                                if (container.CanCurrentPassiveUseStunt(stunt))
                                {
                                    candoList.Add(stunt);
                                }
                            }
                        }
                        resp.stunts = new CharacterPropertyDescription[candoList.Count];
                        for (int i = 0; i < candoList.Count; ++i)
                        {
                            resp.stunts[i] = StreamableFactory.CreateCharacterPropertyDescription(candoList[i]);
                        }
                        return(resp);
                    }
                    else
                    {
                        var resp      = new BattleSceneObjectUsableSkillListMessage();
                        var candoList = new List <SkillType>();
                        foreach (var skillType in SkillType.SkillTypes)
                        {
                            if (container.CanCurrentPassiveUseSkill(skillType.Value))
                            {
                                candoList.Add(skillType.Value);
                            }
                        }
                        resp.skillTypes = new SkillTypeDescription[candoList.Count];
                        for (int i = 0; i < candoList.Count; ++i)
                        {
                            resp.skillTypes[i] = StreamableFactory.CreateSkillTypeDescription(candoList[i]);
                        }
                        return(resp);
                    }
                }

                default:
                    break;
                }
                return(null);
            } catch (Exception e) {
                Logger.WriteLine(e.Message);
                return(null);
            }
        }
        private Message GetCharacterPropertiesDescriptionData(Character character, GetCharacterDataMessage.DataType dataType)
        {
            CharacterPropertiesDescriptionMessage message;

            switch (dataType)
            {
            case GetCharacterDataMessage.DataType.ASPECTS:
                message            = new CharacterAspectsDescriptionMessage();
                message.properties = new CharacterPropertyDescription[character.Aspects.Count];
                for (int i = 0; i < character.Aspects.Count; ++i)
                {
                    message.properties[i] = StreamableFactory.CreateCharacterPropertyDescription(character.Aspects[i]);
                }
                break;

            case GetCharacterDataMessage.DataType.CONSEQUENCES:
                message = new CharacterConsequencesDescriptionMessage();
                if (character.Consequences == null)
                {
                    message.properties = new CharacterPropertyDescription[0];
                }
                else
                {
                    message.properties = new CharacterPropertyDescription[character.Consequences.Count];
                    for (int i = 0; i < character.Consequences.Count; ++i)
                    {
                        message.properties[i] = StreamableFactory.CreateCharacterPropertyDescription(character.Consequences[i]);
                    }
                }
                break;

            case GetCharacterDataMessage.DataType.EXTRAS:
                message = new CharacterExtrasDescriptionMessage();
                if (character.Extras == null)
                {
                    message.properties = new CharacterPropertyDescription[0];
                }
                else
                {
                    message.properties = new CharacterPropertyDescription[character.Extras.Count];
                    for (int i = 0; i < character.Extras.Count; ++i)
                    {
                        message.properties[i] = StreamableFactory.CreateCharacterPropertyDescription(character.Extras[i]);
                    }
                }
                break;

            case GetCharacterDataMessage.DataType.STUNTS:
                message = new CharacterStuntsDescriptionMessage();
                if (character.Stunts == null)
                {
                    message.properties = new CharacterPropertyDescription[0];
                }
                else
                {
                    message.properties = new CharacterPropertyDescription[character.Stunts.Count];
                    for (int i = 0; i < character.Stunts.Count; ++i)
                    {
                        message.properties[i] = StreamableFactory.CreateCharacterPropertyDescription(character.Stunts[i]);
                    }
                }
                break;

            default:
                return(null);
            }
            message.characterID = character.ID;
            return(message);
        }