Jump to content

Snre3n

Community
  • Content Count

    62
  • Joined

  • Last visited

  • Days Won

    21

Posts posted by Snre3n


  1. If you just want it to be smaller, maybe you can modify scaling in characterinfo.txt.
    Not sure what client you are using, so it might not work.
    In top-recode, the client source had it disabled, but easy to enable.

    In characterinfo.txt last 3 floats, eg, 1.0,1.0,1.0 for Long Haired Guy (ID 1) .

    In SceneCreateNode.cpp, function CCharacter* CGameScene::AddCharacter(int nScriptID)

    // added by clp 设置缩放
    	D3DXVECTOR3 scale(pInfo->scaling[0],
    					  pInfo->scaling[1],
    					  pInfo->scaling[2]);
    
    // Comment this out
    	// 读表可能有问题。。暂时不支持缩放
    	//scale.x = 1.0f;
    	//scale.y = 1.0f;
    	//scale.z = 1.0f;

    gJGgBvs.png
     

    • Like 4

  2. @KONG

    Quote

    portal opening time
    send server time once to client (so client and server can have steady beat), initial date and time of portal (only once).
    Calculate opening duration at client side so serverside CPU isnt in use.

     

    ocrjsHeNbD.gif.8aab85145c3021eb744c1c474e1cc49a.gif

     

     

    Code provided is proof of concept only.

     

    Implementation:

    Spoiler

     

    scripts\lua\default\skin\default_new/main.lua

    
    -----------------------------------------------------------------------
    -- View Portal Openings/Closings 
    -----------------------------------------------------------------------
    frmPortalTime = UI_CreateForm("frmPortalTime", FALSE, 0, 0, 350, 200, TRUE, TRUE)
    UI_ShowForm( frmPortalTime, FALSE )
    UI_FormSetHotKey( frmPortalTime, ALT_KEY, HOTKEY_T )
    UI_AddFormToTemplete( frmPortalTime, FORM_MAIN )
    
    list = UI_CreateListView( frmPortalTime, "list", 296, 200, 0, 0, 3, 1)
    UI_LoadListItemImage(list, "texture/ui/NBotton.tga", 1, 1, 100, 171, 296, 21 )
    
    UI_SetListFontColor( list, COLOR_RED, COLOR_RED )
    UI_SetListIsMouseFollow( list, TRUE)
    UI_SetListRowHeight( list, 25 )
    
    id = UI_GetScroll( list )
    UI_SetIsEnabled( id, TRUE )
    
    UI_ListViewSetTitle( list, 0, 100, "", 0, 0, 0, 0 )
    UI_ListViewSetTitle( list, 1, 100, "", 0, 0, 0, 0 )
    UI_ListViewSetTitle( list, 2, 100, "", 0, 0, 0, 0 )

     

    source/inc/Common/NetCommand.h

    
    MESSAGE_DEF(CMD_MC_PORTALTIMES, CMD_MC_BASE + 109, Portal time opening / closing)
    MESSAGE_DEF(CMD_TM_PORTALTIMES, CMD_TM_BASE + 11, Portal time opening/closing)

     

    source/inc/Game_v2.0/UIGlobalVar.h

    
    class CPortalTime;
    extern CPortalTime g_stUIPortalTime;

    source/src/Game_v2.0/UIGlobalVar.cpp

    
    #include "UIPortalTime.h"
    CPortalTime g_stUIPortalTime;

     

    source/inc/Game_v2.0/UIPortalTime.h

    
    #pragma once
    #include "UIGlobalVar.h"
    // Data only
    class Portal {
    public:
    	Portal(std::string destination, time_t entryFirst, time_t entryInterval, time_t entryClose, time_t destinationClose);
    
    	std::string_view Destination() const {
    		return destination;
    	}
    
    //private:
    	std::string destination;
    	time_t entryFirst{0};
    	time_t entryInterval{0};
    	time_t entryClose{0};
    
    	//NOTE: This may be useless data...
    	time_t destinationClose{0};
    };
    
    // Interface for UI only
    namespace GUI {
    class CPortalTime : CUIInterface {
    public:
    	virtual bool Init() override;
    
    	void Add(Portal portal);
    
    private:
    	std::vector<Portal> portals;
    	CForm* frm{nullptr};
    	CListView* list{nullptr};
    
    protected:
    	virtual void FrameMove(DWORD dwTime) override;
    };
    } // namespace GUI

    source/src/Game_v2.0/UIPortalTime.cpp

    
    #include "stdafx.h"
    #include "UIPortalTime.h"
    #include "UIFormMgr.h"
    #include "UIListView.h"
    
    #include <ctime>
    
    Portal::Portal(std::string destination, time_t entryFirst, time_t entryInterval, time_t entryClose, time_t destinationClose)
    	: destination(destination), entryFirst(entryFirst), entryInterval(entryInterval), entryClose(entryClose), destinationClose(destinationClose) {
    }
    
    bool GUI::CPortalTime::Init() {
    	if (frm = CFormMgr::s_Mgr.Find("frmPortalTime"); !frm) {
    		return false;
    	}
    	frm->SetIsDrag(true);
    
    	if (list = dynamic_cast<CListView*>(frm->Find("list")); !list) {
    		return false;
    	}
    	list->GetList()->GetItemImage()->SetColor(COLOR_BLUE);
    	list->GetList()->GetItems()->SetItemMargin(20, 0);
    	list->SetMargin(0, 0, 0, 0);
    	return true;
    }
    
    void GUI::CPortalTime::Add(Portal entrance) {
    	portals.emplace_back(entrance);
    	auto row = list->AddItemRow();
    
    	// Column 1 - Destination
    	auto pItem = new CItem;
    	pItem->SetString(entrance.Destination().data());
    	row->SetIndex(0, pItem);
    
    	// Column 2 - Portal state
    	pItem = new CItem;
    	pItem->SetString("Status");
    	row->SetIndex(1, pItem);
    
    	// Column 3 - Time
    	pItem = new CItem;
    	pItem->SetString("Time");
    	row->SetIndex(2, pItem);
    
    	list->Refresh();
    }
    
    void GUI::CPortalTime::FrameMove(DWORD dwTime) {
    	if (!frm->GetIsShow()) {
    		return;
    	}
    
    	// Update entrance times
    	static tm _tm{};
    	const auto timeNow = time(nullptr);
    	for (auto row = 0; row < portals.size(); ++row) {
    		const auto& portal = portals[row];
    
    
    		auto timeDiff = timeNow - portal.entryFirst;
    
    		static const char* state_opening = "Opening";
    		static const char* state_closing = "Closing";
    		static const char* state_unknwon = "Unknown";
    		auto state = [&]() -> const char* {
    			if (portal.entryInterval) {
    				auto time_open = timeDiff % portal.entryInterval;
    				return time_open > portal.entryClose ? state_opening : state_closing;
    			}
    			return state_unknwon;
    		}();
    
    		auto time_countdown = [&]() -> time_t {
    			if (state == state_opening) {
    				return (timeDiff % portal.entryInterval);
    			}
    			if (state == state_closing) {
    				return portal.entryClose - (timeDiff % portal.entryInterval);
    			}
    			return 0;
    		}();
    
    		//Update state
    		auto pItem = list->GetItemObj(row, 1);
    		pItem->SetString(state);
    
    		//Update time countdown
    		std::tm* p = gmtime(&time_countdown);
    		static char buf[80];
    		strftime(buf, sizeof(buf), "%T", p);
    		pItem = list->GetItemObj(row, 2);
    		pItem->SetString(buf);
    	}
    }

     

    source/src/GameServer/GameAppNet.cpp

    
    // CGameApp::ProcessPacket(GateServer* pGate, RPACKET pkt)
    
    case CMD_TM_PORTALTIMES: {
    			if (m_mapnum <= 0) {
    				break;
    			}
    
    			const auto gatePlayer = READ_LONG(pkt);
    			auto wpk = GETWPACKET();
    			WRITE_CMD(wpk, CMD_MC_PORTALTIMES);
    
    			unsigned short maps_with_portal = 0;
    			for (auto i = 0; i < m_mapnum; ++i) {
    				if (auto& map = m_MapList[i]; map) {
    					if (strcmp(map->m_szEntryMapName, "") == 0) {
    						continue;
    					}
    					if (map->m_SEntryPos.x == 0 && map->m_SEntryPos.y == 0) {
    						continue;
    					}
    					if (time(nullptr) < map->m_tEntryFirstTm) {
    						continue;
    					}
    
    					WRITE_CHAR(wpk, map->GetMapID());
    					WRITE_LONGLONG(wpk, map->m_tEntryFirstTm);
    					WRITE_LONGLONG(wpk, map->m_tEntryTmDis);
    					WRITE_LONGLONG(wpk, map->m_tEntryOutTmDis);
    					WRITE_LONGLONG(wpk, map->m_tMapClsTmDis);
    					++maps_with_portal;
    				}
    			}
    			WRITE_SHORT(wpk, maps_with_portal);
    			WRITE_LONG(wpk, gatePlayer);
    			pGate->SendData(wpk);
    		} break;

    source/src/Game_v2.0/NetIF.cpp

    
    #include "UIPortalTime.h"
    
    // NetIF::HandlePacketMessage(DataSocket* datasock, LPRPACKET pk)
    
    	case CMD_MC_PORTALTIMES: {
    		for (auto portalCount = pk.ReverseReadShort(); portalCount > 0; --portalCount) {
    			static char buf[500];
    
    			const auto mapID = pk.ReadChar();
    			const time_t EntryFirstTm = pk.ReadLongLong();
    			const time_t tEntryTmDis = pk.ReadLongLong();
    			const time_t tEntryOutTmDis = pk.ReadLongLong();
    			const time_t tMapClsTmDis = pk.ReadLongLong();
    			std::string s = GetMapInfo(mapID)->szName;
    			g_stUIPortalTime.Add({static_cast<CMapInfo*>(GetMapInfo(mapID))->szName, EntryFirstTm, tEntryTmDis, tEntryOutTmDis, tMapClsTmDis});
    		}
    	} break;

    source/src/GateServer/ToClient.cpp

    
    // ToClient::CM_BGNPLAY(DataSocket* datasock, RPacket& recvbuf)
    			{
    				auto wpk = g_GateServer->toGameServer->GetWPacket();
    				wpk.WriteCmd(CMD_TM_PORTALTIMES);
    				wpk.WriteLong(MakeULong(player));
    				g_GateServer->toGameServer->SendAllGameServer(wpk);
    			}

    source/src/GateServer/ToGameServer.cpp

    
    // ToGameServer::OnProcessData(DataSocket* datasock, RPacket& recvbuf)	
    case CMD_MC_PORTALTIMES: {
    			RPacket rpk = recvbuf;
    			if (auto player = static_cast<Player*>(MakePointer(rpk.ReverseReadLong())); player) {
    				rpk.DiscardLast(sizeof(sizeof(uLong)));
    				auto wpk = WPacket(rpk).Duplicate();
    				g_GateServer->toClient->SendData(player->m_datasock, wpk);
    			}
    		} break;

     

     

     

     

    • Like 7
    • Thanks 1

  3. XemwEBp.jpg&key=17b49e87ab17a4864e3e5129

    // Function: void CHeadSay::Render( D3DXVECTOR3& pos );
    // Use this as a reference where to insert the code, its already in source. 
    s_dwNamePartsColors[NAME_INDEX][0] = _dwNameColor;
    // 
    
    const stNetChangeChaPart part = _pOwn->GetPart();
    const int id = part.SLink[enumEQUIP_NECK].sID;
    switch (id) {
    case 6611: { // GM's Necklace in iteminfo
    	s_dwNamePartsColors[NAME_INDEX][0] = COLOR_RED;
    } break;
    }
    • Like 1

  4. I5uedJZQpD.gif

     

    //...
    	static char buf[6];
    	const float seconds_remaining = _fPlayTime - _fCurTime;
    	const int minutes = static_cast<int>(seconds_remaining / 60);
    	const int seconds = static_cast<int>(seconds_remaining - (minutes * 60));
    	minutes > 1 ? _snprintf_s(buf, _TRUNCATE, "%.2d:%.2d", minutes, seconds)
    				: seconds > 1 ? _snprintf_s(buf, _TRUNCATE, "%d", seconds)
    							  : _snprintf_s(buf, _TRUNCATE, "%.1f", seconds_remaining);
    
    	CGuiFont::s_Font.BRender(0, buf, x, y, COLOR_RED, COLOR_BLACK);
    } // End of function void CAniClock::Render(int x, int y);

     

    • Like 5
    • Thanks 4

  5. @Sk3let0n

    I guess it would be possible to move everything from LUA to C++, but why would you?
    It would be time consuming and I'm thinking that it would also make everything a lot harder to make changes to, especially since you would have to recompile source.

    By embedding LUA in the server/game executables you can add/remove content without having to recompile your executables.

    At client you can see the convenient use of LUA, making UI very customizable,

    As for server, take a look inside  /resource/script/ folder.

     

    LUA is there for a good reason.


     

    • Like 1
×
×
  • Create New...