Guest User

BaseGameMode.h

a guest
Oct 11th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.63 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "Game/LoadoutBuilderComponent.h"
  4. #include "Soldier/Soldier.h"
  5. #include "Player/BasePlayerController.h"
  6. #include "GameFramework/GameMode.h"
  7. #include "BaseGameMode.generated.h"
  8.  
  9. UENUM(BlueprintType)
  10. enum class ETeamModeEnum : uint8
  11. {
  12.     MultipleTeams,
  13.     OneTeam,
  14.     FreeForAll,
  15. };
  16.  
  17. UCLASS()
  18. class FPSTEMPLATE_API ABaseGameMode : public AGameMode
  19. {
  20.     GENERATED_BODY()
  21.  
  22.     // Loadout builder
  23.     UPROPERTY()
  24.         ULoadoutBuilderComponent * LoadoutBuilderComponent;
  25.  
  26.     TSubclassOf<ASoldier> SoldierClass;
  27.  
  28. public:
  29.     // Widget class used for game mode specific score display
  30.     UPROPERTY(BlueprintReadOnly, Category = GameMode)
  31.         TSubclassOf<UUserWidget> ScoreWidgetClass;
  32.  
  33.     // Whether players can cause damage to their teammates
  34.     UPROPERTY(BlueprintReadOnly, Category = GameMode)
  35.         bool bFriendlyFire;
  36.  
  37.     // Whether players may spawn with their custom loadout, if not DefaultLoadout will be used
  38.     UPROPERTY(BlueprintReadOnly, Category = GameMode)
  39.         bool bUseCustomLoadout;
  40.  
  41.     // Loadout to use for every player if custom loadouts are not allowed
  42.     UPROPERTY(BlueprintReadOnly, Category = GameMode)
  43.         FLoadoutStruct DefaultLoadout;
  44.  
  45.     // Set whether player can select team, all players play against each other or all players play in one team
  46.     UPROPERTY(BlueprintReadOnly, Category = GameMode)
  47.         TEnumAsByte<ETeamModeEnum> TeamMode;
  48.    
  49.     // Constructor
  50.     ABaseGameMode(const FObjectInitializer & ObjectInitializer);
  51.  
  52.     virtual void InitGameState() override;
  53.  
  54.     virtual void PostLogin(APlayerController * NewPlayer) override;
  55.  
  56.     virtual void Logout(AController * Exiting) override;
  57.  
  58.     virtual void Reset() override;
  59.  
  60.     // Will move a player to the correct state after login
  61.     virtual void MovePlayerToEntryState(ABasePlayerController * PC);
  62.  
  63.     // Called when match time expired
  64.     virtual void OnTimeExpired();
  65.  
  66.     // Ends this match, no team wins
  67.     virtual void EndMatch() override;
  68.  
  69.     // End the match with specified winner team
  70.     void EndMatch(ETeamEnum WinnerTeam);
  71.  
  72.     // End match with specified player as winner
  73.     void EndMatch(ABasePlayerState * WinnerPS);
  74.  
  75.     // Move all player controllers to NewState
  76.     void MoveAllPlayersToState(EPlayerStateEnum::Type NewState);
  77.  
  78.     // Calcuate damage amount for player, by default it only disable friendly fire if bFriendlyFire == false
  79.     virtual void CalcDamage(float & OutDamageAmount, ABasePlayerController * PC, ABasePlayerController * OtherPC);
  80.  
  81.     // Called when a soldier dies from any damage
  82.     void OnSoldierDied(ASoldier * Soldier, const FDamageEvent & DamageEvent, ABasePlayerController * EventInstigator, AActor * DamageCauser);
  83.  
  84.     // Overrideable event for when any player died
  85.     virtual void OnPlayerDied(ABasePlayerController * PC);
  86.    
  87. protected:
  88.     // Overrideable event for when a player killed an enemy player
  89.     virtual void OnPlayerKilledEnemy(const FDamageEvent & DamageEvent, ABasePlayerController * PC, ABasePlayerController * OtherPC);
  90.  
  91.     // Overrideable event for when a player killed a friendly player
  92.     virtual void OnPlayerKilledTeammate(const FDamageEvent & DamageEvent, ABasePlayerController * PC, ABasePlayerController * OtherPC);
  93.  
  94. public:
  95.     int32 GetNumPlayersInTeam(ETeamEnum Team) const;
  96.  
  97.     // Player wants to join a team
  98.     void PlayerJoinTeam(ABasePlayerController * PC, ETeamEnum InTeam);
  99.  
  100.     // Automatically join team, based on player count
  101.     void PlayerAutoJoinTeam(ABasePlayerController * PC);
  102.  
  103. protected:
  104.     // Overrideable, returns whether specified player may join a team
  105.     virtual bool CanPlayerJoinTeam(ABasePlayerController * PC, ETeamEnum InTeam) const;
  106.  
  107. public:
  108.     // Player wants to spawn
  109.     void PlayerSpawn(ABasePlayerController * PC);
  110.    
  111.     // Overrideable, return whether player may spawn
  112.     virtual bool CanPlayerSpawn(ABasePlayerController * PC) const;
  113.  
  114.     // Return the loadout to use for player
  115.     virtual const FLoadoutStruct & GetPlayerLoadout(ABasePlayerController * PC) const;
  116.  
  117.     // Evaluate loadout and set it on player controller
  118.     void PlayerSetLoadout(ABasePlayerController * PC, const FLoadoutStruct & Loadout);
  119.  
  120.     // Kick player
  121.     UFUNCTION(BlueprintCallable, Category = GameMode)
  122.         virtual bool KickPlayer(ABasePlayerController * KickedPlayer, const FText & KickReason);
  123.  
  124.     // Travel to new map
  125.     UFUNCTION(BlueprintCallable, Category = GameMode)
  126.         virtual void ServerTravel(const FString & MapName);
  127.  
  128.     // Broadcast chat message to all clients
  129.     void BroadcastChatMessage(ABasePlayerController * FromPC, const FString & Message, bool bTeamOnly);
  130.  
  131. protected:
  132.     // Whether one player is allowed to receive the chat message from another player
  133.     virtual bool CanPlayerReceiveChatMessage(ABasePlayerController * FromPC, ABasePlayerController * ToPC, bool bTeamOnly);
  134.  
  135. };
Add Comment
Please, Sign In to add comment