2019-09-23 07:50:21 +08:00
|
|
|
#include "main.h"
|
|
|
|
#include "cwmods/cwmods.h"
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <stdio.h>
|
2018-10-16 05:59:05 +08:00
|
|
|
|
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
float GetMilliseconds(int hour, int minute){
|
|
|
|
return (hour * 60 * 60 * 1000) + (minute * 60 * 1000);
|
|
|
|
}
|
2018-10-16 05:59:05 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
void CommandsModMessage(wchar_t message[]){
|
|
|
|
cube::Game* game = cube::GetGame();
|
|
|
|
game->chat_widget->PrintMessage(L"[");
|
|
|
|
game->chat_widget->PrintMessage(L"CommandsMod", 255, 140, 0);
|
|
|
|
game->chat_widget->PrintMessage(L"] ");
|
|
|
|
game->chat_widget->PrintMessage(message);
|
|
|
|
}
|
2018-10-16 05:59:05 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
int DotsToMapCoord(long long coord) {
|
|
|
|
return (coord - 0x2000000) / (cube::DOTS_PER_BLOCK * cube::BLOCKS_PER_MAP_CHUNK);
|
|
|
|
}
|
2018-10-16 05:59:05 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
long long MapCoordToDots(int coord) {
|
|
|
|
return ((long long)coord * cube::DOTS_PER_BLOCK * cube::BLOCKS_PER_MAP_CHUNK) + 0x2000000;
|
2018-10-17 02:55:24 +08:00
|
|
|
}
|
2018-10-16 05:59:05 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
EXPORT int HandleChat(wchar_t* msg) {
|
|
|
|
cube::Game* game = cube::GetGame();
|
|
|
|
cube::Host* host = &game->host;
|
|
|
|
cube::World* world = &host->world;
|
2018-10-16 05:59:05 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
wchar_t response[256];
|
2018-10-16 05:59:05 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
int targetx, targety;
|
2018-10-17 08:47:48 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
int targetHour, targetMinute;
|
2018-10-17 02:55:24 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
if ( swscanf(msg, L"/settime %d:%d", &targetHour, &targetMinute) == 2){
|
|
|
|
printf("%ld:%ld\n", targetHour, targetMinute);
|
|
|
|
float targetMS = GetMilliseconds(targetHour, targetMinute);
|
2018-10-17 02:55:24 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
float maxTime = GetMilliseconds(24, 0);
|
|
|
|
float minTime = GetMilliseconds(0, 0);
|
2018-10-17 06:49:16 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
if (targetMS > maxTime) targetMS = maxTime;
|
|
|
|
else if (targetMS < minTime) targetMS = minTime;
|
2018-10-16 05:59:05 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
world->time = targetMS;
|
2018-10-16 05:59:05 +08:00
|
|
|
|
2019-09-23 07:50:21 +08:00
|
|
|
swprintf(response, L"Changing time to %d:%02d.\n", targetHour % 24, targetMinute % 60);
|
2018-10-17 02:55:24 +08:00
|
|
|
CommandsModMessage(response);
|
2019-09-23 07:50:21 +08:00
|
|
|
return 1;
|
2018-10-16 05:59:05 +08:00
|
|
|
}
|
2019-09-23 07:50:21 +08:00
|
|
|
else if (!wcscmp(msg, L"/coords")){
|
|
|
|
cube::Creature* player = game->GetPlayer();
|
|
|
|
swprintf(response, L"World coordinates:\nX: %lld\nY: %lld\nZ: %lld\n", player->position.x, player->position.y, player->position.z);
|
2018-10-17 02:55:24 +08:00
|
|
|
CommandsModMessage(response);
|
2019-09-23 07:50:21 +08:00
|
|
|
return 1;
|
2018-10-16 05:59:05 +08:00
|
|
|
}
|
2019-09-23 07:50:21 +08:00
|
|
|
else if ( swscanf(msg, L"/tp %d %d", &targetx, &targety) == 2){
|
|
|
|
cube::Creature* player = game->GetPlayer();
|
|
|
|
player->position.x = MapCoordToDots(targetx);
|
|
|
|
player->position.y = MapCoordToDots(targety);
|
2018-10-16 06:22:15 +08:00
|
|
|
swprintf(response, L"Teleporting.\n");
|
2018-10-17 02:55:24 +08:00
|
|
|
CommandsModMessage(response);
|
2019-09-23 07:50:21 +08:00
|
|
|
return 1;
|
2018-10-16 05:59:05 +08:00
|
|
|
}
|
2019-09-23 07:50:21 +08:00
|
|
|
return 0;
|
2018-10-16 05:59:05 +08:00
|
|
|
}
|