Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fcc9182
initial fork
Aug 11, 2023
c43adc6
(bugfix) multiple event subscribes
Aug 11, 2023
1507c6f
(wip) refctor Initator flow
Aug 11, 2023
1eed4c0
(wip) counteroffer flow refactor
Aug 11, 2023
23b0dc8
(fix) updated Friend list + avatar type
Aug 11, 2023
27ff2a2
friend list integration
Aug 11, 2023
9242f02
major cleanup, documenting + bugfixes
Aug 11, 2023
2894a55
fixed many flow issues
Aug 11, 2023
11fcc60
(bugfix) wrong offer names in UI + UI not updating for second counter…
Aug 14, 2023
6e72a28
(bugfix) scaled icons
Aug 14, 2023
f86e627
Merge pull request #17 from abixbg/player-trading
oliverfcarson Aug 14, 2023
93e8746
added ITradingDatastore (caching can be disabled now)
Aug 15, 2023
8b4e0a3
(fixed) unsubscribe issues
Aug 15, 2023
2875448
Merge pull request #19 from abixbg/player-trading
oliverfcarson Aug 15, 2023
e078bb5
Trading Updates
oliverfcarson Aug 15, 2023
20ed161
(fixed) lock in case respondent immediately accept/refuse a trade
Aug 16, 2023
e811948
Merge branch 'player-trading' of https://github.com/PubNubDevelopers/…
Aug 16, 2023
437fbf9
(fixed) offer withrawn before respondent accepted/refused
Aug 16, 2023
eb3ad71
Merge branch 'main' into pr/21
oliverfcarson Sep 5, 2023
50301d1
Merge branch 'main' into player-trading
oliverfcarson Sep 6, 2023
9e2bacb
Updating Connector Object
oliverfcarson Sep 6, 2023
06d3f9a
Revert "Updating Connector Object"
oliverfcarson Sep 6, 2023
d86a997
Merge branch 'player-trading' into player-trading
oliverfcarson Sep 6, 2023
6d2ab79
Merge pull request #21 from abixbg/player-trading
oliverfcarson Sep 6, 2023
0430e15
Player Trading Integration
oliverfcarson Sep 14, 2023
85790a9
Interactivity & Name Change Updates
oliverfcarson Sep 18, 2023
bca262a
Game Length & Bug Fixes
oliverfcarson Sep 18, 2023
6aea932
README Updates & Code Cleanup
oliverfcarson Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,591 changes: 1,231 additions & 360 deletions Assets/SuperMultiplayerShooter/MainMenu.unity

Large diffs are not rendered by default.

29 changes: 27 additions & 2 deletions Assets/SuperMultiplayerShooter/Scripts/CharacterSelector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using PubnubApi;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

Expand All @@ -17,6 +18,9 @@ public class CharacterSelector : MonoBehaviour
public Connector connector;
public SampleMainMenu mainMenu;

private Pubnub pubnub { get { return PNManager.pubnubInstance.pubnub; } }


void Start()
{
DataCarrier.characters = characters;
Expand All @@ -43,7 +47,7 @@ public void Refresh()
}

// Character selection:
public void SelectCharacter(CharacterData data)
public async void SelectCharacter(CharacterData data)
{
// Close the character selection panel:
mainMenu.characterSelectionPanel.SetActive(false);
Expand All @@ -58,6 +62,27 @@ public void SelectCharacter(CharacterData data)
}

mainMenu.characterIconPresenter.sprite = data.icon;

//Update local metadata
var metadata = PNManager.pubnubInstance.CachedPlayers[pubnub.GetCurrentUserId()].Custom;
if (metadata != null)
{
if (metadata.ContainsKey("chosen_character"))
{
metadata["chosen_character"] = DataCarrier.chosenCharacter;
}

//First time saving a new hat.
else
{
metadata.Add("chosen_character", DataCarrier.chosenCharacter);
}

PNManager.pubnubInstance.CachedPlayers[pubnub.GetCurrentUserId()].Custom = metadata;

//Store the new update in the metadata
await PNManager.pubnubInstance.UpdateUserMetadata(pubnub.GetCurrentUserId(), PNManager.pubnubInstance.CachedPlayers[pubnub.GetCurrentUserId()].Name, metadata);
}
}
}
}
5 changes: 3 additions & 2 deletions Assets/SuperMultiplayerShooter/Scripts/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void JoinCustomGame(PNRoomInfo room){
// changes (e.g. they go offline) on the same channel but there are other ways to implement a lobby and
// room system with PubNub. Alternatively you could use PubNub's message history
// to store a created room, then others could read a channel's history to decide which room to join.
public async Task<bool> CreateCustomGame(int selectedMap, int maxPlayers, bool allowBots)
public async Task<bool> CreateCustomGame(int selectedMap, int maxPlayers, bool allowBots, int gameLength)
{
if (pubnub != null)
{
Expand All @@ -282,6 +282,7 @@ public async Task<bool> CreateCustomGame(int selectedMap, int maxPlayers, bool a
metaData["started"] = 0;
metaData["map"] = selectedMap;
metaData["customAllowBots"] = allowBots ? 1 : 0;
metaData["gameLength"] = gameLength * 60; //Match Duration will be set in seconds
string channelName = PubNubUtilities.chanGlobal;
PNResult<PNSetStateResult> setPresenceStateResponse = await pubnub.SetPresenceState()
.Channels(new string[] { channelName })
Expand Down Expand Up @@ -625,6 +626,7 @@ private async Task<bool> UserIsOnlineOrStateChange(string uuid)
int map = System.Convert.ToInt32(userState["map"]);
int maxPlayers = System.Convert.ToInt32(userState["maxPlayers"]);
bool allowBots = (System.Convert.ToInt32(userState["customAllowBots"]) == 1);
GAME_LENGTH_MAKE_ME_CONFIGURABLE = System.Convert.ToInt32(userState["gameLength"]);
string ownerId = (string)userState["ownerId"];
bool inProgress = System.Convert.ToInt32(userState["inProgress"]) == 1;
PNRoomInfo roomInfo = new PNRoomInfo(uuid, name, map, maxPlayers, allowBots, roomCounter, GAME_LENGTH_MAKE_ME_CONFIGURABLE);
Expand Down Expand Up @@ -1057,7 +1059,6 @@ public void PlayerSelected(string action, string id)

/// <summary>
/// Returns the language of the user
/// TODO: Will be replaced by getting the metadata of the user.
/// </summary>
/// <returns></returns>
public string GetUserLanguage()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using PubnubApi;
using PubNubUnityShowcase;
using UnityEngine;

Expand All @@ -23,6 +25,8 @@ public class CharacterCustomizer : MonoBehaviour
List<InventorySlot> curSlots = new List<InventorySlot>(); // the current instatiated slots
PlayerController preview; // the instantiated player prefab for preview

private Pubnub pubnub { get { return PNManager.pubnubInstance.pubnub; } }

// Start is called before the first frame update
void Start()
{
Expand Down Expand Up @@ -103,7 +107,7 @@ public void RefreshSlots(){
/// <summary>
/// Equips an item from the database:
/// </summary>
public void Equip(CosmeticItemData item){
public async void Equip(CosmeticItemData item){

switch (item.itemType){
case CosmeticType.Hat:
Expand All @@ -117,6 +121,27 @@ public void Equip(CosmeticItemData item){
// Refresh the player preview:
Cosmetics c = new Cosmetics(DataCarrier.chosenHat);
playerPrefabController.cosmeticsManager.Refresh(c);

//Update metadata
var metadata = PNManager.pubnubInstance.CachedPlayers[pubnub.GetCurrentUserId()].Custom;
if(metadata != null)
{
if(metadata.ContainsKey("chosen_hat"))
{
metadata["chosen_hat"] = DataCarrier.chosenHat;
}

//First time saving a new hat.
else
{
metadata.Add("chosen_hat", DataCarrier.chosenHat);
}

PNManager.pubnubInstance.CachedPlayers[pubnub.GetCurrentUserId()].Custom = metadata;

//Store the new update in the metadata
await PNManager.pubnubInstance.UpdateUserMetadata(pubnub.GetCurrentUserId(), PNManager.pubnubInstance.CachedPlayers[pubnub.GetCurrentUserId()].Name, metadata);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ private async void OnPnMessage(PNMessageResult<object> result)
if(acceptFriend != null)
{
acceptFriend.tradeButton.gameObject.SetActive(true);
acceptFriend.tradeButton.interactable = false; //To be removed once trading is fully integrated.
acceptFriend.acceptButton.gameObject.SetActive(false);
acceptFriend.removeButton.name = "remove"; // Used to determine whether or not to remove from friend groups
acceptFriend.gameObject.GetComponent<Image>().color = Color.white; // change color to show accepted friend.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using PubnubApi;
using PubNubUnityShowcase;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
Expand Down Expand Up @@ -30,9 +31,9 @@ public void Set(string uuid, string name)
userId = uuid;
onlineStatus.color = Color.gray;
messageButton.onClick.AddListener(() => OnMessageClick());
//tradeBtn.onClick.AddListener(() => OnTradeClick()); To update when trade is implemented.
acceptButton.onClick.AddListener(async () => await OnAcceptFriendClick());
removeButton.onClick.AddListener(async () => await OnRemoveClick());
tradeButton.onClick.AddListener(() => OnTradeClick());
}

/// <summary>
Expand All @@ -45,9 +46,11 @@ public void OnMessageClick()
/// <summary>
/// Called when the user clicks the trade button
/// </summary>
public void OnTradeClick()
public async void OnTradeClick()
{
//TODO, once player trading is integrated.
var cts = new CancellationTokenSource();
var viewData = await TradingService.Instance.GetViewDataInitiator(userId, cts.Token);
var view = TradingService.Instance.OpenView(viewData, cts.Token);
}
/// <summary>
/// Remove friend
Expand Down
3 changes: 1 addition & 2 deletions Assets/SuperMultiplayerShooter/Scripts/Leaderboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ private async Task<bool> PublishMessage(string text, string channel)
/// <param name="result"></param>
private void OnPnMessage(PNMessageResult<object> result)
{
// Enable the button once we have established connection to PubNub, todo it is better to use a status listener here.
// Leaderboard Updates
// Enable the button once we have established connection to PubNub
if (result.Channel.Equals(PubNubUtilities.chanLeaderboardSub))
{
Dictionary<string, object> msg = JsonConvert.DeserializeObject<Dictionary<string, object>>(result.Message.ToString());// as Dictionary<string, object>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class LobbyBrowserUI : MonoBehaviour
public Text mapNameText;
public SelectorUI mapSelector;
public SelectorUI playerNumberSelector;
public SelectorUI gameLengthSelector;
public Toggle enableBotsOption;

[Header("Joined Screen:")]
Expand Down Expand Up @@ -133,7 +134,7 @@ public void Leave()
}
}
public async void Create(){
await Connector.instance.CreateCustomGame(mapSelector.curSelected, playerNumberSelector.items[playerNumberSelector.curSelected].value, enableBotsOption.isOn);
await Connector.instance.CreateCustomGame(mapSelector.curSelected, playerNumberSelector.items[playerNumberSelector.curSelected].value, enableBotsOption.isOn, gameLengthSelector.items[gameLengthSelector.curSelected].value);
}
public void StartGame(){
Connector.instance.StartCustomGame();
Expand Down
24 changes: 17 additions & 7 deletions Assets/SuperMultiplayerShooter/Scripts/PNManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class PNManager : PNManagerBehaviour
public PNPresenceEvent onPubNubPresence;
public delegate void PNObjectEvent(PNObjectEventResult result); // Receive app context (metadata) updates
public PNObjectEvent onPubNubObject;
public delegate void PNStatusEvent(PNStatus status); // Receive status updates
public PNStatusEvent onPubNubStatus;
public delegate void PubNubReady(); // PubNub is initialized, ok to call PubNub object
public PubNubReady onPubNubReady;

Expand Down Expand Up @@ -95,6 +97,7 @@ public async Task InitializePubNub()
pnListener.onSignal += OnPnSignal;
pnListener.onObject += OnPnObject;
pnListener.onPresence += OnPnPresence;
pnListener.onStatus += OnPnStatus;
await SubscribeToStaticChannels();
try { onPubNubReady(); } catch (System.Exception) { }
}
Expand Down Expand Up @@ -168,6 +171,17 @@ private void OnPnObject(Pubnub pn, PNObjectEventResult result)
catch (System.Exception) { }
}

// Handler for PubNub Status event.
private void OnPnStatus(Pubnub pn, PNStatus status)
{
// Notify other listeners
try
{
onPubNubStatus(status);
}
catch (System.Exception) { }
}

protected virtual new void OnDestroy()
{
// Don't want the default destroy behaviour
Expand Down Expand Up @@ -251,6 +265,9 @@ public async Task<bool> GetUserMetadata(string Uuid)
customData["hats"] = JsonConvert.SerializeObject(Connector.instance.GenerateRandomHats());
customData["language"] = LocalizationSettings.SelectedLocale.Identifier.Code;
customData["60fps"] = false;
customData["chosen_hat"] = DataCarrier.chosenHat;
customData["chosen_character"] = DataCarrier.chosenCharacter;

// Update
await UpdateUserMetadata(pubnub.GetCurrentUserId(), pubnub.GetCurrentUserId(), customData);
}
Expand Down Expand Up @@ -331,13 +348,6 @@ public async Task<bool> UpdateUserMetadata(string uuid, string name, Dictionary<
Custom = setUuidMetadataResult.Custom,
Updated = setUuidMetadataResult.Updated
};

//Update hat inventory.
if (setUuidMetadataResult.Custom != null && setUuidMetadataResult.Custom.ContainsKey("hats"))
{
List<int> availableHats = JsonConvert.DeserializeObject<List<int>>(setUuidMetadataResult.Custom["hats"].ToString());
Connector.instance.UpdateAvailableHats(availableHats);
}

//Existing player
if (PNManager.pubnubInstance.CachedPlayers.ContainsKey(setUuidMetadataResult.Uuid))
Expand Down
Loading