Page 1 of 1

Странный баг с торговлей

Posted: 26.12.2012 5:24
by sith_apprentice
Хочу написать простой скрипт, чтобы чар принимал вещи, которые ему дают друзья и клал в банк. Первую вещь он берет и кладет в банк, но в тот момент когда я кидаю на него вторую, Stealth зависает. Что не так?

(upd причина креша найдена, см след пост)

Code: Select all

Program Tax_Collector;

const
	LogType=$1BDD;   // type of logs
	GoldType = $0EED; // type of gold coins
 

	DelayBankingInProgress = 3000; // wait for how long between putting different things into the bank box
	TaxingLength = 30*60; // collect for 30 minutes
	TaxCheckDelay = 5; // how often to check if we have the trade window opened
	TradeTimeout = 25; // if the status of that window didn't change during that time interval then dismiss it
	TradeDelay = 1000; // how often to check if the trade is confirmed

	Mine = 1;
	His = 2;

var
	FriendList:array of string; // don't be afraid of these people; collect stuff from them
	BankID,TakenObjID:cardinal;
	TaxCollectingStarted,TradeWindowOpenedAt:Int64;
	HisName:string; // name of the taxed char
	i,j:integer;
begin
// people we are going to tax
FriendList := ['loser1','loser2','loser3'];

// open the bank box
	UOSay('bank');
	wait(DelayBankingInProgress);
	BankID := ObjAtLayer(BankLayer);
// record the time when we started collecting
	TaxCollectingStarted := DateTimeToUnix(Now);
	
// the colelcting process:
	repeat
		if IsTrade then
		begin  
      j:=0;
			// someone wants to give us something
			//for j:=0 to TradeCount-1 do // check all the trade windows
			//begin     
      
				//if ((not IsTrade) or (not GetTradeOpponent(j)>0)) then Break; // something bad happened, start over
				HisName := GetTradeOpponentName(j);
				for i:= Low(FriendList) to High(FriendList) do
				if (BMSearch(1,Hisname,FriendList[i]) > 0) then
				begin
					//it's a friend, accept the items:
					TradeWindowOpenedAt := DateTimeToUnix(Now);
					repeat
						if  TradeCheck(j,His) then // he confirmed the trade
							if not TradeCheck(j,Mine) then ConfirmTrade(j);
						wait(TradeDelay); 
					until ((abs(DateTimeToUnix(Now)-TradeWindowOpenedAt) > TradeTimeOut) or (not IsTrade) or not (GetTradeOpponent(j)>0));
					if (IsTrade) then CancelTrade(j);
          Break;
				end else begin
					AddToSystemJournal(HisName+' wants to trade with me, I`ve no idea who it is');
					if (IsTrade) then CancelTrade(j);
				end;    
      //  break;
			//end;
			  
		end;
		
		// check if we were given  gold:
		TakenObjID := FindType(GoldType, Backpack);
		while ( TakenObjID > 0) do
		begin
			MoveItems(BackPack, GoldType, $FFFF, BankID, 0,0,0, DelayBankingInProgress);
			TakenObjID := FindType(GoldType, Backpack);
		end;
		
		// check if we were given  logs:
		TakenObjID := FindType(LogType, Backpack);
		while ( TakenObjID > 0) do
		begin
			MoveItems(BackPack, LogType, $FFFF, BankID, 0,0,0, DelayBankingInProgress);
			TakenObjID := FindType(LogType, Backpack);
		end;
		
		wait(TaxCheckDelay); 
	until (abs(DateTimeToUnix(Now)-TaxCollectingStarted) > TaxingLength);

end.

Re: Странный баг с торговлей

Posted: 26.12.2012 5:56
by sith_apprentice
Как оказалось стелс падал из за

Code: Select all

until ((abs(DateTimeToUnix(Now)-TradeWindowOpenedAt) > TradeTimeOut) or (not IsTrade) or not (GetTradeOpponent(j)>0));
части. Если Trade окно закрыто и вызвать GetTradeOpponent(TradeNum), то после этого стелс крешнется как только на чара перетащить предмет. (Т.е падает не сразу после GetTradeOpponent а только потом)


Если исправить на

Code: Select all

until ((abs(DateTimeToUnix(Now)-TradeWindowOpenedAt) > TradeTimeOut) or (not IsTrade) );


то все работает хорошо

Re: Странный баг с торговлей

Posted: 26.12.2012 23:56
by Vizit0r
занятный баг.
исправлено.

Re: Странный баг с торговлей

Posted: 29.12.2012 10:14
by sith_apprentice
У меня еще один странный баг с торговлей -- в некоторых обстоятельствах можно получить флаг IsTrade=True и при этом TradeCount=0 :mrgreen:

Кмк, происходит это так: чар1 хочет дать чару2 вещь, кидает ее на чара2 и открывает трейд окно. Тем временем чар2 решает телепортироваться куда подальше. Вещь падает чару1 в бекпак и он с ней остается. У чара2 теперь этот странный баг (у чара1 вроде нет или я просто не заметила). Остановка скрипта и реконнект не помогают сброситьт IsTrade -- только перезапуск стелса :(