Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ sysinfo.txt
# Builds
*.apk
*.unitypackage
/.vsconfig
5 changes: 1 addition & 4 deletions Assets/Scripts/Dungeon/DungeonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,7 @@ private void RewardPlayers()
{
lock (mutex)
{
foreach (var player in joinedPlayers)
{
Dungeon.RewardPlayer(player, yieldSpecialReward);
}
Dungeon.RewardPlayers(joinedPlayers, yieldSpecialReward);
}
}

Expand Down
30 changes: 18 additions & 12 deletions Assets/Scripts/Game/Controllers/DungeonController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using RavenNest.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using UnityEngine;

public class DungeonController : MonoBehaviour
Expand Down Expand Up @@ -290,8 +291,18 @@ public IEnumerator HideDungeon(float afterSeconds)
}
}

internal void RewardPlayer(PlayerController player, bool generateMagicAttributes)
internal void RewardPlayers(List<PlayerController> joinedPlayers, bool yieldSpecialReward)
{
var type = yieldSpecialReward ? DropType.MagicRewardGuaranteed : DropType.StandardGuaranteed;
ItemDrops.DropItemForPlayers(joinedPlayers, type);
foreach(var player in joinedPlayers)
{
GivePlayerExp(player);
}
}

internal void GivePlayerExp(PlayerController player)
{
if (!ItemDrops) return;

var exp = GameMath.CombatExperience(bossCombatLevel / 5);
Expand All @@ -300,15 +311,8 @@ internal void RewardPlayer(PlayerController player, bool generateMagicAttributes
player.AddExp(yieldExp, Skill.Slayer);
player.AddExpToActiveSkillStat(yieldExp);

//if (!player.AddExpToCurrentSkill(yieldExp))
// player.AddExp(yieldExp, Skill.Slayer);

var type = generateMagicAttributes ? DropType.MagicRewardGuaranteed : DropType.StandardGuaranteed;
for (var i = 0; i < itemRewardCount; ++i)
{
ItemDrops.DropItem(player, type);
}
}
//drops moved to ItemDropHandler
}
internal void DisableContainer()
{
dungeonContainer.SetActive(false);
Expand All @@ -326,4 +330,6 @@ internal void EnableContainer()
room.ResetRoom();
}
}


}
123 changes: 113 additions & 10 deletions Assets/Scripts/Game/Handlers/ItemDropHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using RavenNest.Models;
using System.Text;

public class ItemDropHandler : MonoBehaviour
{
Expand All @@ -22,14 +24,52 @@ public void SetDropList(ItemDropList droplist)
items = dropList.Items;
}

public void DropItem(PlayerController player,
DropType dropType = DropType.Standard,
string messageStart = "You found")
internal void DropItemForPlayers(List<PlayerController> joinedPlayers, DropType dropType = DropType.Standard, int itemRewardCount = 1)
{
if (items == null || items.Length == 0)
{
return;

Dictionary<Item, List<string>> playerListByItem = new Dictionary<Item, List<string>>(); //List<PlayerController> if more details needed
List<string> playerList;

foreach (PlayerController player in joinedPlayers)
{
if (player != null) continue;

for (var i = 0; i < itemRewardCount; ++i)
{
var itemRecieved = DropItem(player, dropType);
if (itemRecieved == null)
continue;

bool? EquipIfBetter = player.PickupItem(itemRecieved);
if (EquipIfBetter == null)
continue;

string playerName = player.Name;
if (EquipIfBetter ?? false)
playerName += "*"; //* denote item was equipped

if (playerListByItem.TryGetValue(itemRecieved, out playerList)) //add to list of item with a player, otherwise add player to existing item
{

playerList.Add(playerName);
}
else
{
playerList = new List<string>();
playerList.Add(playerName);
playerListByItem.Add(itemRecieved, playerList);
}
}
}

AlertPlayers(playerListByItem);
}

public Item DropItem(PlayerController player,
DropType dropType = DropType.Standard)
{
var guaranteedDrop = dropType == DropType.MagicRewardGuaranteed || dropType == DropType.StandardGuaranteed;

var dropitems = this.items.ToList();
Expand All @@ -43,7 +83,7 @@ public void DropItem(PlayerController player,
var allItems = gameManager.Items.GetItems();
var droppableItems = dropitems.Select(x =>
{
RavenNest.Models.Item item = allItems.FirstOrDefault(y =>
Item item = allItems.FirstOrDefault(y =>
y.Name.StartsWith(x.ItemName ?? "", StringComparison.OrdinalIgnoreCase) ||
y.Name.StartsWith(x.ItemID, StringComparison.OrdinalIgnoreCase) ||
y.Id.ToString().ToLower() == x.ItemID.ToLower());
Expand All @@ -62,17 +102,78 @@ public void DropItem(PlayerController player,

foreach (var item in droppableItems)
{
//if (player.Stats.Attack.Level < item.Item.RequiredAttackLevel ||
// player.Stats.Defense.Level < item.Item.RequiredDefenseLevel)
// continue;

if (UnityEngine.Random.value <= item.DropChance)
{
player.PickupItem(item.Item, messageStart);
return;
if (!player.IsBot)
return null;

return item.Item;
}
}
} while (guaranteedDrop);

return null;
}

//Send Message Winning loot, limited by 500 text
//Formatted like so, sending new message if last string goes over 500 text
/*
* Victorious! The loots have gone to these players: Loot Name:- UserName1 & Username2!! Other Loot:- UserName4 & UserName7!!
*/
internal void AlertPlayers(Dictionary<Item, List<string>> playerListByItem)
{
try
{
int maxMessageLenght = 500; //Set to max lenght that can be transmitted over twitch
string messageStart = "Victorious! The loots have gone to these players: "; //first part of the message
StringBuilder sb = new StringBuilder(100, maxMessageLenght);
int rollingCount = messageStart.Length;
sb.Append(messageStart);

foreach (KeyValuePair<Item, List<string>> kvItem in playerListByItem) //for each keypair
{
Item thisItem = kvItem.Key;
string name = name = thisItem.Name;

if (thisItem.Category == ItemCategory.StreamerToken)
{
name = this.gameManager.RavenNest.TwitchDisplayName + " Token"; //convert streamertoken to correct name
}
name += ":- "; //add :-

if (rollingCount + name.Length >= maxMessageLenght) //check that we don't appending a message over max Lenght
{
gameManager.RavenBot.Send(null, sb.ToString(), null); //send and clear if we do
sb.Clear();
}
sb.Append(name);
rollingCount = sb.Length;

List<string> playerInList = kvItem.Value; //get list of players that gotten this loot
int totalplayerInList = playerInList.Count;

for (int i = 0; i < totalplayerInList; i++)
{
string playerName = playerInList[i];
playerName += (i + 1) == totalplayerInList ? "!! " : " & "; //append !! to last player in the list, & if not
if (rollingCount + playerName.Length >= maxMessageLenght) //message check
{
gameManager.RavenBot.Send(null, sb.ToString().Trim(), null);
sb.Clear();
}
sb.Append(playerName);
rollingCount = sb.Length;
}
}

if (sb.Length > 0)
gameManager.RavenBot.Send(null, sb.ToString(), null); //I think RavenBot catches empty string, I don't think we'll get an empty char or few
}
catch (Exception ex)
{
//TODO - most likely error is over Max cap for StringBuilder, set maxMessageLenght
}
}

private void AddMonthDrop(List<ItemDrop> droplist, int monthStart, int monthsLength, string itemName, string itemId, float maxDropRate, float minDropRate)
Expand All @@ -94,6 +195,8 @@ private void AddMonthDrop(List<ItemDrop> droplist, int monthStart, int monthsLen
});
}
}


}

public enum DropType
Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/Game/Handlers/RaidHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ public void OnLeave(bool raidWon, bool raidTimedOut)

++player.Statistics.RaidsWon;

var itemDrop = gameManager.Raid.Boss.GetComponent<ItemDropHandler>();
if (itemDrop)
{
itemDrop.DropItem(player);
}
//var itemDrop = gameManager.Raid.Boss.GetComponent<ItemDropHandler>();
//if (itemDrop)
//{
// itemDrop.DropItem(player, DropType.StandardGuaranteed, "you found");
//} moved to ItemDropHandler
}

if (raidTimedOut)
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Game/Managers/RaidManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,13 @@ public void EndRaid(bool bossKilled, bool timeout)
camera.DisableFocusCamera();
ScheduleNextRaid();
notifications.HideRaidInfo();
var itemDrop = gameManager.Raid.Boss.GetComponent<ItemDropHandler>();

lock (mutex)
{
var playersToLeave = raidingPlayers.ToList();
if(itemDrop != null && bossKilled) //Only when is killed should players be rewarded
itemDrop.DropItemForPlayers(playersToLeave, DropType.StandardGuaranteed);
foreach (var player in playersToLeave)
{
Leave(player, bossKilled, timeout);
Expand Down
37 changes: 23 additions & 14 deletions Assets/Scripts/Game/Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using UnityEngine.AI;
using Resources = RavenNest.Models.Resources;
using Debug = Shinobytes.Debug;

public class PlayerController : MonoBehaviour, IAttackable
{
private static readonly ConcurrentDictionary<string, int> combatTypeArgLookup
Expand Down Expand Up @@ -757,23 +758,31 @@ public bool PickupEventItem(Guid id)
return false;
}

public void PickupItem(Item item, string messageStart = "You found")
//return boolean based on EquipIfBetter, null if IsBot or Item is null
public bool? PickupItem(Item item)
{
if (item == null) return;
if (item == null) return null;
AddItem(item);
var itemName = item.Name;
if (item.Category == ItemCategory.StreamerToken)
{
itemName = this.gameManager.RavenNest.TwitchDisplayName + " Token";
}
if (EquipIfBetter(item))
{
if (IsBot) return;
gameManager.RavenBot.Send(PlayerName, messageStart + " and equipped a {itemName}!", itemName);
return;
}
if (IsBot) return;
return !IsBot ? EquipIfBetter(item) : null;
}
public bool? PickupItem(Item item, string messageStart = "You found")
{
if (item == null) return null;
AddItem(item);
var itemName = item.Name;
if (item.Category == ItemCategory.StreamerToken)
{
itemName = this.gameManager.RavenNest.TwitchDisplayName + " Token";
}
if (EquipIfBetter(item))
{
if (IsBot) return null;
gameManager.RavenBot.Send(PlayerName, messageStart + " and equipped a {itemName}!", itemName);
return true;
}
if (IsBot) return null;
gameManager.RavenBot.Send(PlayerName, messageStart + " a {itemName}!", itemName);
return false;
}

public PlayerState BuildPlayerState()
Expand Down
12 changes: 6 additions & 6 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
"com.unity.burst": "1.7.0-pre.1",
"com.unity.cloud.userreporting": "0.2.4-preview",
"com.unity.collab-proxy": "1.13.5",
"com.unity.ide.rider": "3.0.7",
"com.unity.ide.visualstudio": "2.0.12",
"com.unity.ide.rider": "3.0.12",
"com.unity.ide.visualstudio": "2.0.14",
"com.unity.ide.vscode": "1.2.4",
"com.unity.mathematics": "1.2.5",
"com.unity.memoryprofiler": "0.4.2-preview.1",
"com.unity.memoryprofiler": "0.4.4-preview.2",
"com.unity.performance.profile-analyzer": "1.1.1",
"com.unity.polybrush": "1.1.2",
"com.unity.postprocessing": "3.1.1",
"com.unity.render-pipelines.universal": "12.1.0",
"com.unity.searcher": "4.9.1",
"com.unity.test-framework": "1.1.29",
"com.unity.test-framework": "1.1.30",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.6.2",
"com.unity.toolchain.win-x86_64-linux-x86_64": "0.1.21-preview",
"com.unity.timeline": "1.6.4",
"com.unity.toolchain.win-x86_64-linux-x86_64": "1.0.0",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down
Loading