Commit 311dce39 authored by Kegan's avatar Kegan

Rework chat handling

parent f065614a
......@@ -4,8 +4,6 @@ class BattleRoyaleBase
{
void BattleRoyaleBase()
{
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "SendGlobalMessage", this );
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "SendClientMessage", this );
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "RequestAutowalk", this );
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "IncreaseStats", this );
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "RequestSuicide", this );
......@@ -17,7 +15,6 @@ class BattleRoyaleBase
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "SetRoundForPlayer", this);
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "SetWeaponTexture", this);
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "SetShirtTexture", this);
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "GlobalChat", this );
}
bool allowFallDamage(PlayerBase plr)
......@@ -35,36 +32,7 @@ class BattleRoyaleBase
}
void GlobalChat(CallType type, ref ParamsReadContext ctx, ref PlayerIdentity sender, ref Object target)
{
Param1< string > data;
if( !ctx.Read( data ) ) return;
if(type == CallType.Client)
{
if(! GetGame().GetPlayer() ) return;
PlayerBase me = PlayerBase.Cast(GetGame().GetPlayer());
if(!me) return;
me.MessageAction( data.param1 );
}
if(type == CallType.Server)
{
if(!target) return;
PlayerBase targetBase = PlayerBase.Cast(target);
if(!targetBase) return;
if(!targetBase.GetIdentity()) return;
string message = "(Global) " + targetBase.GetIdentity().GetName() + ": " + data.param1;
ref Param1<string> value_string = new Param1<string>(message);
GetRPCManager().SendRPC( RPC_DAYZBR_NAMESPACE, "GlobalChat", value_string, false );
}
}
void SetShirtTexture(CallType type, ref ParamsReadContext ctx, ref PlayerIdentity sender, ref Object target)
{
Param1< string > data;
......@@ -129,51 +97,6 @@ class BattleRoyaleBase
GetRPCManager().SendRPC( RPC_DAYZBR_NAMESPACE, "SetWeaponTexture", value_string, false , NULL, targetBase);
}
}
void SendGlobalMessage( CallType type, ref ParamsReadContext ctx, ref PlayerIdentity sender, ref Object target )
{
Param1< string > data;
if( !ctx.Read( data ) ) return;
if( GetGame() )
{
string msg = data.param1;
PlayerBase me = PlayerBase.Cast(GetGame().GetPlayer());
if(!msg.Contains("ALL: "))
{
if(me.my_round)
{
if(msg.Contains(me.my_round))
{
msg.Replace(me.my_round + ": ","");
GetGame().Chat( msg, "colorImportant" );
}
}
}
else
{
msg.Replace("ALL: ","");
GetGame().Chat( msg, "colorImportant" );
}
}
}
void SendClientMessage( CallType type, ref ParamsReadContext ctx, ref PlayerIdentity sender, ref Object target )
{
Param1< string > data;
if( !ctx.Read( data ) ) return;
if ( type == CallType.Client )
{
PlayerBase player = PlayerBase.Cast( target );
if ( !player ) return;
player.MessageImportant( data.param1 );
}
}
void RequestAutowalk( CallType type, ref ParamsReadContext ctx, ref PlayerIdentity sender, ref Object target )
{
Param1< bool > data;
......
modded class Chat
{
override void Add(ChatMessageEventParams params)
{
BRLOG("Chat message received");
super.Add(params);
}
//custom BR method for adding text to chat
void Add(string text)
{
BRLOG("Add #1: " + text);
ChatMessageEventParams msgParams = new ChatMessageEventParams(0,text,"","");
Add(msgParams);
}
void Add(string name, string text)
{
BRLOG("Add #2: " + name + ": " + text);
ChatMessageEventParams msgParams = new ChatMessageEventParams(0,name,text,"");
Add(msgParams);
}
}
\ No newline at end of file
......@@ -5,11 +5,11 @@ class BrChatMenu extends ChatInputMenu
protected ref Timer new_m_close_timer;
static int m_current_channel = 0;
protected ref MissionBase new_m_mission;
protected MissionGameplay new_m_mission;
void BrChatMenu(ref MissionBase m_mission)
void BrChatMenu(MissionBase m_mission)
{
new_m_mission = m_mission;
new_m_mission = MissionGameplay.Cast(m_mission);
new_m_close_timer = new Timer();
}
......
......@@ -29,8 +29,93 @@ modded class MissionGameplay
{
super.OnInit();
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "GlobalChat", this );
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "SendGlobalMessage", this );
GetRPCManager().AddRPC( RPC_DAYZBR_NAMESPACE, "SendClientMessage", this );
BR_GAME = new BattleRoyale( NULL );
}
//Global Chat handling (need to directly add chat messages to chat)
//TODO: if this works, use more in depth chat add functionality?
void GlobalChat(CallType type, ref ParamsReadContext ctx, ref PlayerIdentity sender, ref Object target)
{
Param1< string > data;
if( !ctx.Read( data ) ) return;
if(type == CallType.Client)
{
if(! GetGame().GetPlayer() ) return;
PlayerBase me = PlayerBase.Cast(GetGame().GetPlayer());
if(!me) return;
if(!m_Chat) return;
m_Chat.Add(data.param1);
}
if(type == CallType.Server)
{
if(!target) return;
PlayerBase targetBase = PlayerBase.Cast(target);
if(!targetBase) return;
if(!targetBase.GetIdentity()) return;
string message = "(Global) " + targetBase.GetIdentity().GetName() + ": " + data.param1;
ref Param1<string> value_string = new Param1<string>(message);
GetRPCManager().SendRPC( RPC_DAYZBR_NAMESPACE, "GlobalChat", value_string, false );
}
}
void SendGlobalMessage( CallType type, ref ParamsReadContext ctx, ref PlayerIdentity sender, ref Object target )
{
Param1< string > data;
if( !ctx.Read( data ) ) return;
if( GetGame() )
{
string msg = data.param1;
PlayerBase me = PlayerBase.Cast(GetGame().GetPlayer());
if(!msg.Contains("ALL: "))
{
if(me.my_round)
{
if(msg.Contains(me.my_round))
{
msg.Replace(me.my_round + ": ","");
m_Chat.Add(msg);
}
}
}
else
{
msg.Replace("ALL: ","");
m_Chat.Add(msg);
}
}
}
void SendClientMessage( CallType type, ref ParamsReadContext ctx, ref PlayerIdentity sender, ref Object target )
{
Param1< string > data;
if( !ctx.Read( data ) ) return;
if ( type == CallType.Client )
{
PlayerBase player = PlayerBase.Cast( target );
if ( !player ) return;
m_Chat.Add(msg);
}
}
//Unlock gesture menu
override void OnKeyPress(int key)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment