Jump to content

Empire bonuses remaining time


Go to solution Solved by VegaS™,

Recommended Posts

  • Active Member

Hello guys,

I want to extend a ChatPacket info for empire bonuses. As everyone know, you can see the bonus info in the chat when some empire bonus is active. I need to do an extension which will show remaining time to the end of the bonuses since you can set empire bonuses for selected time.

Example notice:

Drop rate is set for 20% and remaining time to the end of bonus is 2 hours and 2 minutes.

I would be really glad if someone can find a way how to do that.

Thanks for answers!

Sincerely,

ReFresh

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • Forum Moderator

You can try something like this:

// priv_manager.h
time_t GetPrivRemainedTimeByEmpire(BYTE bEmpire, BYTE type);
		
// priv_manager.cpp
time_t CPrivManager::GetPrivRemainedTimeByEmpire(BYTE bEmpire, BYTE type)
{
	const auto* pkPrivEmpireData = GetPrivByEmpireEx(bEmpire, type);
	if (pkPrivEmpireData && pkPrivEmpireData->m_end_time_sec)
		return pkPrivEmpireData->m_end_time_sec - get_global_time();
	return 0;
}

// How-To-Use
// PRIV_ITEM_DROP, PRIV_GOLD_DROP, PRIV_GOLD10_DROP, PRIV_EXP_PCT
static auto& priv_manager = CPrivManager::instance();
const auto item_drop_time = priv_manager.GetPrivRemainedTimeByEmpire(ch->GetEmpire(), PRIV_ITEM_DROP);
const auto item_drop_bonus = priv_manager.GetPriv(ch, PRIV_ITEM_DROP);

if (item_drop_bonus)
{
	const auto hours = item_drop_time / 3600;
	const auto minutes = (item_drop_time % 3600) / 60;
	ch->ChatPacket(CHAT_TYPE_NOTICE, "Drop rate: %d%%, active for: %ld hours and %ld minutes!", item_drop_bonus, hours, minutes);
}

If it works, then you can extend _send_bonus_info function based on my example.

 

 

252310GreenCheck.pngUPDATE: I tested it in game, this is the result. Ignore the previous part of tutorial.

fbb9ef9f074552357cff21245c3caad6.png

Srcs/Server/game/src/input_login.cpp

Search for:

static void _send_bonus_info(LPCHARACTER ch)
{
	int	item_drop_bonus = 0;
	int gold_drop_bonus = 0;
	int gold10_drop_bonus	= 0;
	int exp_bonus		= 0;

	item_drop_bonus		= CPrivManager::instance().GetPriv(ch, PRIV_ITEM_DROP);
	gold_drop_bonus		= CPrivManager::instance().GetPriv(ch, PRIV_GOLD_DROP);
	gold10_drop_bonus	= CPrivManager::instance().GetPriv(ch, PRIV_GOLD10_DROP);
	exp_bonus			= CPrivManager::instance().GetPriv(ch, PRIV_EXP_PCT);

	if (item_drop_bonus)
	{
		ch->ChatPacket(CHAT_TYPE_NOTICE,
				LC_TEXT("¾ÆÀÌÅÛ µå·Ó·ü  %d%% Ãß°¡ À̺¥Æ® ÁßÀÔ´Ï´Ù."), item_drop_bonus);
	}
	if (gold_drop_bonus)
	{
		ch->ChatPacket(CHAT_TYPE_NOTICE,
				LC_TEXT("°ñµå µå·Ó·ü %d%% Ãß°¡ À̺¥Æ® ÁßÀÔ´Ï´Ù."), gold_drop_bonus);
	}
	if (gold10_drop_bonus)
	{
		ch->ChatPacket(CHAT_TYPE_NOTICE,
				LC_TEXT("´ë¹Ú°ñµå µå·Ó·ü %d%% Ãß°¡ À̺¥Æ® ÁßÀÔ´Ï´Ù."), gold10_drop_bonus);
	}
	if (exp_bonus)
	{
		ch->ChatPacket(CHAT_TYPE_NOTICE,
				LC_TEXT("°æÇèÄ¡ %d%% Ãß°¡ ȹµæ À̺¥Æ® ÁßÀÔ´Ï´Ù."), exp_bonus);
	}
}

Replace it with the following function:

This is the hidden content, please

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 7
  • Good 1
  • Love 5
Link to comment
Share on other sites

  • Active Member
55 minutes ago, VegaS™ said:
// priv_manager.h
time_t GetPrivRemainedTimeByEmpire(BYTE bEmpire, BYTE type);
		
// priv_manager.cpp
time_t CPrivManager::GetPrivRemainedTimeByEmpire(BYTE bEmpire, BYTE type)
{
	const auto* pkPrivEmpireData = GetPrivByEmpireEx(bEmpire, type);
	if (pkPrivEmpireData && pkPrivEmpireData->m_end_time_sec)
		return pkPrivEmpireData->m_end_time_sec - get_global_time();
	return 0;
}

// How-To-Use
// PRIV_ITEM_DROP, PRIV_GOLD_DROP, PRIV_GOLD10_DROP, PRIV_EXP_PCT
static auto& priv_manager = CPrivManager::instance();
const auto item_drop_time = priv_manager.GetPrivRemainedTimeByEmpire(ch->GetEmpire(), PRIV_ITEM_DROP);
const auto item_drop_bonus = priv_manager.GetPriv(ch, PRIV_ITEM_DROP);

if (item_drop_bonus)
{
	const auto hours = item_drop_time / 3600;
	const auto minutes = (item_drop_time % 3600) / 60;
	ch->ChatPacket(CHAT_TYPE_NOTICE, "Drop rate: %d%%, active for: %ld hours and %ld minutes!", item_drop_bonus, hours, minutes);
}

So I don't need to add this part right?

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • Active Member

@VegaS™ And if I want to add seconds too? I need to show them only when time is lower than a hour.

So when is remaining time lower than a hour it will show this:

remaining time is: 59 minutes and 30 seconds.

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • Forum Moderator
6 minutes ago, ReFresh said:

@VegaS™ And if I want to add seconds too?

 

const auto second = total_seconds % 60;
Link to comment
Share on other sites

  • Active Member

@VegaS™ Thank you very much, and the last two things.

We have a fuc*ing language declension so I need to do some check for the time value, so that I can change the ChatPacket output based on time remaining at each bonus.

We have something like this in our language:

1 minute - 1 minuta

2 minutes - 2 minuty

1 second - 1 sekunda

2 seconds - 2 sekundy

5 seconds - 5 sekund

That's why I need this check.

 

And also I need to show seconds only when the time is lower than an hour, but I can do it alone if I'll have some check for remaining time.

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • Forum Moderator
  • Solution

3c1166655ef9c249dbdf79297decad49.png  cd60134720060f8153c85f6c210768b1.png
 

 

This is the hidden content, please

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 7
  • Good 5
  • Love 5
Link to comment
Share on other sites

  • Active Member

@VegaS™ I just spent a couple hours by braining how to change the text depending on what time is. And I couldn't get any working solution. I just wanted to do something like this:

Spoiler
for_0_seconds_and_for_5_seconds_and_for_more_than_5_seconds_text = "sekund"
only_for_1_second_text = "sekunda"
from_2_seconds_to_4_seconds_text = "sekundy"

for_0_minutes_and_for_5_minutes_and_for_more_than_5_minutes_text = "minut"
only_for_1_minute_text = "minuta"
from_2_minutes_to_4_minutes_text = "minuty"

for_0_and_5_hours_and_for_more_than_5_hours_text = "hodin"
for_1_hour_text = "hodina"
from_2_to_4_hours_text = "hodiny"
  
That's the problem of our language.
English has only 2 phrases for the time that means: 1 second, 2 seconds... 1 minute 2 minutes... 1 hour 2 hours... our language has 3 phrases.

 

I tried something like this, but it didn't work:

Spoiler
			if (hours < 1)
				snprintf(buf, sizeof(buf), "%d minut a %d sekund", minutes, seconds); //THIS WORKS RIGHT
			
			else if (hours == 1)
				snprintf(buf, sizeof(buf), "%d hodina a %d minut", hours, minutes); //THIS WORKS RIGHT
			
			else if (hours >= 2 && hours <= 4 && minutes >= 2 && minutes <= 4)
				snprintf(buf, sizeof(buf), "%d hodiny a %d minuty", hours, minutes); //THIS DOESN'T WORK
			
			else if (hours < 1 && minutes == 1 && seconds == 1)
				snprintf(buf, sizeof(buf), "%d minuta a %d sekunda", minutes, seconds); //THIS DOESN'T WORK
			
			else if (hours < 1 && minutes >= 2 && minutes <= 4 && seconds >= 2 && seconds <= 4)
				snprintf(buf, sizeof(buf), "%d minuty a %d sekundy", minutes, seconds); //THIS DOESN'T WORK

 

I had one idea, define the time text separately and then add some "<=, >=, ==" and then write it into a snprintf as defined thing and on that operators base it will show the relevant text for time. I was searching some way how to do it, but I wasn't successful.

I will be really glad for your answer, if you will have some free time to do that. Thanks

Edited by ReFresh
  • Love 1

I'll be always helpful! 👊 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Similar Content

  • Activity

    1. 3

      Crystal Metinstone

    2. 3

      Feeding game source to LLM

    3. 113

      Ulthar SF V2 (TMP4 Base)

    4. 3

      Feeding game source to LLM

    5. 0

      Target Information System

    6. 3

      Feeding game source to LLM

    7. 2

      anti exp explanation pls

  • Recently Browsing

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.