整数转换为魔兽世界金币

发布于 2024-09-25 08:32:25 字数 205 浏览 2 评论 0原文

对于 MMORPG 魔兽世界,我正在尝试编写一个库。该游戏中的金钱以整数形式存储,而游戏货币不是整数,而是基于金币、银币和铜币。

每100铜为1银,每100银为1金。

现在我需要将这样的整数转换为 WoW Money 格式:例如

123123 应该返回: 23c 31s 12g

任何人都知道如何做到这一点

For a MMORPG World of Warcraft im trying to write a lib. Money in that games is stored as an Integer and in game currency is not an integer it's based of Gold, Silver and Copper coins.

Every 100 copper is 1 silver and every 100 silver is 1 gold.

Now I need to convert such an integer to the WoW Money format: for example

123123 should return:
23c 31s 12g

Anyone knows how to do this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

辞旧 2024-10-02 08:32:26

C#:

int[] WoWMoney(int m)
{
        int[] result = new int[3];
        int copper = m % 100;
        m = (m - copper) / 100;
        int silver = m % 100;
        int gold = (m - silver) / 100;
        result[0] = copper;
        result[1] = silver;
        result[2] = gold;
        return result;
}

C#:

int[] WoWMoney(int m)
{
        int[] result = new int[3];
        int copper = m % 100;
        m = (m - copper) / 100;
        int silver = m % 100;
        int gold = (m - silver) / 100;
        result[0] = copper;
        result[1] = silver;
        result[2] = gold;
        return result;
}
我们的影子 2024-10-02 08:32:26

Python:

def fmtGold(value):
    return "%sc %ss %sg"%(value%100,value/100%100,value/10000%100) 

python:

def fmtGold(value):
    return "%sc %ss %sg"%(value%100,value/100%100,value/10000%100) 
潇烟暮雨 2024-10-02 08:32:26
  1. 将整数除以10 000(铜换算成黄金),取整数部分,就是黄金的数量。
  2. 取上一步的余数。除以100(铜换银),就是银的数量。
  3. 取上一步的余数。它将是铜。
  1. Divide integer by 10 000 (copper in gold), take the integer part, it will be the amount of gold.
  2. Take remainder from previous step. Divide by 100 (copper in silver), it will be the amount of silver.
  3. Take remainder from previous step. It will be copper.
此生挚爱伱 2024-10-02 08:32:26

首先将 123123 除以 10000。得到 12.3123。整数(12)是黄金数字。剩下的(分度数之后)3123 除以 100 即可获得银牌。这将为您提供 31.23。同样,第一部分 (31) 是银,其余部分 (23) 是铜。

例如,在 C++ 中,该算法如下所示

int number = 123123;
int gold = number/10000; //this will give you the whole part because of the int type
number = number%10000; //this will make 'number' 3123
int silver = number/100; //this will get the silver
int copper = number%100; //this will get the copper

First of all devide 123123 to 10000. This gives you 12.3123. The whole number (12) is the gold number. The rest (after the delimeter) 3123 devide to 100 to get the silver. This gives you 31.23. Again the first part (31) is the silver and the rest (23) is your copper.

In C++ for instance, this algorithm will look like

int number = 123123;
int gold = number/10000; //this will give you the whole part because of the int type
number = number%10000; //this will make 'number' 3123
int silver = number/100; //this will get the silver
int copper = number%100; //this will get the copper
你与昨日 2024-10-02 08:32:26

珀尔:

print "How much : ";
$money = <>;
chomp $money;

$gold = int($money/10000);
$money = int($money%10000);
$silver = int($money/100);
$copper = int($money%100);


$result = sprintf("You need : %dg %ds %dc", $gold, $silver, $copper);
print "\n$result\n";

<>;

Perl :

print "How much : ";
$money = <>;
chomp $money;

$gold = int($money/10000);
$money = int($money%10000);
$silver = int($money/100);
$copper = int($money%100);


$result = sprintf("You need : %dg %ds %dc", $gold, $silver, $copper);
print "\n$result\n";

<>;
独自←快乐 2024-10-02 08:32:26

我将 Necro 这个主题,因为这是 Google 的第一个结果。

虚幻引擎的解决方案(这里是UE5):
输入图片这里的描述

在这种情况下,“Money”是更新函数的输入参数。

“Spliting”(是的,一个“t”)是分割值(fe 100),一个局部变量。也可以作为输入。

I will Necro this Topic, since it is the first result at Google.

The Solution for Unreal (UE5 here):
enter image description here

“Money” in this case, is the Input Parameter of the Update Function.

“Spliting” (yes, one “t”) is the splitting value (f.e. 100), a local Variable. Can be an input, too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文