Example #1
0
        void handlePlayerActions(List <PlayerAction.Action> actions)
        {
            foreach (PlayerAction.Action action in actions)
            {
                switch (action.type)
                {
                case PlayerAction.Type.LeftClick:
                    handleLeftClickAsCharacterSelection(action);
                    break;

                case PlayerAction.Type.ReleaseLeftMouseButton:

                    break;

                case PlayerAction.Type.DoubleClick:
                    handleDoubleClick(action);
                    break;

                case PlayerAction.Type.RightClick:
                    if (player.hasCharacterSelected())
                    {
                        world.handleRightClickWhenCharacterIsSelected((PlayerAction.RightClick)action, player.getSelectedCharacter());
                    }
                    break;


                case PlayerAction.Type.PlaceExcavationMarker:
                    PlayerAction.PlaceExcavationMarker click = (PlayerAction.PlaceExcavationMarker)action;
                    Ray ray = click.getRay();
                    world.placeExcavationBlockAlongRay(ray);
                    break;

                case PlayerAction.Type.PlayerBuildBlock:
                    PlayerAction.PlayerBuildBlock placementClick = (PlayerAction.PlayerBuildBlock)action;
                    Ray placementRay = placementClick.getRay();
                    world.placeBlockAlongRay(placementRay, player.getSelectedBlockType());
                    break;

                case PlayerAction.Type.PlayerDestoryBlock:
                    PlayerAction.PlayerDestroyBlock destructionClick = (PlayerAction.PlayerDestroyBlock)action;
                    Ray destructionTay = destructionClick.getRay();
                    world.destroyBlockAlongRay(destructionTay);
                    break;


                case PlayerAction.Type.ExcavationMouseover:
                    world.HandleExcavationMouseover(((PlayerAction.ExcavationMouseHover)action).getRay());
                    break;

                case PlayerAction.Type.BoatPlacementMouseover:
                    world.HandleBoatPlacementMouseover(((PlayerAction.BoatPlacementHover)action).getRay());
                    break;

                case PlayerAction.Type.BlockPlanPlacementHover:
                    world.HandleBlockPlanPlacementMouseover(((PlayerAction.BlockPlanPlacementHover)action).getRay());
                    break;

                case PlayerAction.Type.BoatPlacement:
                    world.HandleBoatJobsitePlacement(((PlayerAction.BoatPlacement)action).getRay());
                    break;

                case PlayerAction.Type.CharacterPlacement:
                    world.handleCharacterPlacement(((PlayerAction.CharacterPlacement)action).getRay());
                    break;

                case PlayerAction.Type.DeleteWorksiteClick:
                    world.handleDeleteWorksite(((PlayerAction.RemoveWorksiteClick)action).getRay());
                    break;


                case PlayerAction.Type.StartDragging:
                    PlayerAction.StartDragging starDragClick = (PlayerAction.StartDragging)action;
                    Ray     startFarmRay   = starDragClick.getRay();
                    Vector3?firstDragBlock = world.getBlockAlongRay(startFarmRay);
                    if (firstDragBlock.HasValue)
                    {
                        player.setFirstBlockInDrag(new BlockLoc((Vector3)firstDragBlock));
                    }
                    break;


                case PlayerAction.Type.Dragging:
                    handleDragging(action);
                    break;


                case PlayerAction.Type.FinishDragging:
                    handleFinishDragging(action);
                    break;


                case PlayerAction.Type.PlaceWoodBlockPlan:
                    Ray placeWoodBlockClickRay = ((PlayerAction.MouseAction)action).getRay();
                    world.placeWoodBlockPlanAlongRay(placeWoodBlockClickRay, player.getSelectedBlockType());
                    break;


                case PlayerAction.Type.RemoveWoodBlockPlan:
                    Ray removeWoodBlockClickRay = ((PlayerAction.MouseAction)action).getRay();
                    world.removeWoodBlockPlanAlongRay(removeWoodBlockClickRay);
                    break;



                case PlayerAction.Type.setCameraLocation:
                    player.setCameraLoc(((PlayerAction.SetCameraLocation)action).newCameraLocation, (((PlayerAction.SetCameraLocation)action).getNeckAdjustment()));
                    break;

                case PlayerAction.Type.MoveBy:
                    PlayerAction.MoveBy    moveBy       = (PlayerAction.MoveBy)action;
                    AxisAlignedBoundingBox oldMoveAABB  = player.getThirdPersonAABB();
                    AxisAlignedBoundingBox goalMoveAABB = player.getThirdPersonAABB();
                    goalMoveAABB.loc += moveBy.moveBy;

                    AxisAlignedBoundingBox newMoveAABB = world.AABBPhysicsCollisionOnly(oldMoveAABB, moveBy.moveBy);

                    //AxisAlignedBoundingBox newAABB = world.AABBPhysicsCollisionOnly(move.currentAABB, move.desiredAABB);

                    player.setCameraLoc(newMoveAABB.middle());
                    break;


                case PlayerAction.Type.Quit:
                    main.Exit();
                    break;

                case PlayerAction.Type.Save:
                    saveGame();
                    break;

                case PlayerAction.Type.NewGame:
                    newGame();
                    break;

                case PlayerAction.Type.LoadGame:
                    loadGame();
                    break;

                case PlayerAction.Type.DisembodyCharacter:
                    player.disembodyCharacter();
                    break;

                case PlayerAction.Type.DeselectCharacter:
                    player.deselectCharacter();
                    break;

                case PlayerAction.Type.JobTypeSwitch:
                    player.getSelectedCharacter().setJobType(((PlayerAction.JobTypeSwitch)action).getJobType());
                    break;

                default:
                    throw new Exception("unhandled player action " + action.type);
                }
            }
        }