112 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| #include "mn_aidb_persist"
 | |
| 
 | |
| void debug( object oPC, string text )
 | |
| {
 | |
|    SendMessageToPC( oPC, text );
 | |
| }
 | |
| 
 | |
| void main()
 | |
| {
 | |
|     object oItem;
 | |
|     string sResRef;
 | |
|     object oPC = GetLastClosedBy();
 | |
|     int plotitem = 0;
 | |
|     object erdai;
 | |
|     float valuemod = 0.20f;
 | |
|     int totalvalue = 0;
 | |
|     int numberOfCherries = 0;
 | |
|     string tag;
 | |
|     int doneflag;
 | |
|     int tempvalue;
 | |
|     float calcvalue;
 | |
| 
 | |
| 
 | |
|      // Calculate value of items and number of cherries
 | |
|      oItem = GetFirstItemInInventory();
 | |
|      while(GetIsObjectValid(oItem))
 | |
|      {
 | |
|         doneflag = FALSE;
 | |
|         tag = GetTag( oItem );
 | |
|         if ( tag == "food_cherie" )
 | |
|         {
 | |
|            numberOfCherries += 1;
 | |
|            //debug( oPC, "Cherry donated" );
 | |
|            SetPlotFlag( oItem, FALSE );
 | |
|            DestroyObject( oItem, 0.1f );
 | |
|            doneflag = TRUE;
 | |
|         }
 | |
| 
 | |
|         if ( tag == "NW_IT_GOLD001" )
 | |
|         {
 | |
|            totalvalue += GetItemStackSize( oItem );
 | |
|            // debug( oPC, "Item "+GetTag(oItem)+" sold for "+ IntToString (GetItemStackSize( oItem )) );
 | |
|            DestroyObject( oItem, 0.1f );
 | |
|            doneflag = TRUE;
 | |
|         }
 | |
| 
 | |
|         if (!doneflag && GetPlotFlag( oItem ) )
 | |
|         {
 | |
|            plotitem+=1;
 | |
|            doneflag = TRUE;
 | |
|         }
 | |
| 
 | |
|         if (!doneflag)
 | |
|         {
 | |
|            // Saelg item
 | |
|            tempvalue = GetGoldPieceValue( oItem );
 | |
|            calcvalue = IntToFloat( tempvalue );
 | |
|            calcvalue *= valuemod;
 | |
|            tempvalue = FloatToInt (calcvalue);
 | |
|            totalvalue += tempvalue;
 | |
|            // debug( oPC, "Item "+GetTag(oItem)+" sold for "+ IntToString (tempvalue) );
 | |
|            DestroyObject( oItem, 0.1f );
 | |
|         }
 | |
| 
 | |
|         oItem = GetNextItemInInventory();
 | |
|      }
 | |
| 
 | |
|      if (plotitem > 0)
 | |
|      {
 | |
|         erdai = GetObjectByTag( "MN_ERDAI" );
 | |
|         string preface = (plotitem>1)?"Some items ":"An item ";
 | |
| 
 | |
|         if (GetIsObjectValid( erdai ))
 | |
|         {
 | |
|            AssignCommand( erdai, ActionSpeakString( preface+"could not be sold - please collect them from the chest, friend." ) );
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|            FloatingTextStringOnCreature( preface+"could not be sold - you should pick them up from the chest.", oPC, FALSE);
 | |
|         }
 | |
|      }
 | |
| 
 | |
|      erdai = GetObjectByTag( "MN_ERDAI" );
 | |
|      string thankyou = "Thank you, friend! Your donation is much appreciated!";
 | |
| 
 | |
|      if ( totalvalue >0 || numberOfCherries > 0 )
 | |
|      {
 | |
|         if (GetIsObjectValid( erdai ))
 | |
|         {
 | |
|            AssignCommand( erdai, ActionSpeakString( thankyou ) );
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|            FloatingTextStringOnCreature( thankyou, oPC, FALSE);
 | |
|         }
 | |
| 
 | |
|         int newcherry = GetEnergy() + (numberOfCherries*CHERRY2ENERGY);
 | |
|         SetEnergy( newcherry );
 | |
| 
 | |
|         int remainder = totalvalue % 2;
 | |
|         int money = totalvalue / 2;
 | |
| 
 | |
|         int op = money + GetOpGold() + remainder;
 | |
|         SetOpGold( op );
 | |
| 
 | |
|         int cha = money + GetChaGold();
 | |
|         SetChaGold( cha );
 | |
|      }
 | |
| 
 | |
| //     debug (oPC, "Total: "+IntToString( totalvalue )+ " GP, Cherries: "+IntToString( numberOfCherries ) );
 | |
| }
 |