OSStatus GetIntervalValue(u16* value) { return ObjectGetValue(ObjDevice, DistInterval, value); }
OSStatus GetRemindValue(u16* value) { return ObjectGetValue(ObjDevice, DistRemind, value); }
OSStatus GetEnergyValue(u16* value) { return ObjectGetValue(ObjDevice, DistEnergy, value); }
// Object send Dist Query Response Message static OSStatus ObjectDistQueryRespMsgSend(char* obj_name, char* dist_name, u8 ds, SthreadId receiver, u16 trans_id) { OSStatus err = kUnknownErr; SysComMsg* msg = NULL; SapiObjectDistNameQueryResp* resp_msg = NULL; mico_rtos_lock_mutex(&ObjectMutex); msg = SysComCreateMsg(API_OBJECT_DISTNAME_QUERY_RESP_MSG, sizeof(SapiObjectDistNameQueryResp), trans_id, ESM_OBJECT_THREAD_ID, receiver); if(msg == NULL) { Object_ERR("ObjectDistQueryRespMsgSend: Message is NULL"); err = kNoMsgErr; goto ObjectDistQueryRespMsgSend_RET; } resp_msg = (SapiObjectDistNameQueryResp*)SysComGetPayload(msg); strncpy(resp_msg->objName, obj_name, strlen(obj_name)); strncpy(resp_msg->distName, dist_name, strlen(dist_name)); resp_msg->dsType = ds; switch(ds) { case EDistType_Data: err = ObjectGetValue(obj_name, dist_name, &(resp_msg->data)); break; case EDistType_String: err = ObjectGetString(obj_name, dist_name, resp_msg->str); break; default: Object_ERR("ObjectDistQueryRespMsgSend: Unknow dsType(%d)", resp_msg->dsType); break; } switch(err) { case kNoErr: resp_msg->status = ESubOK; strncpy(resp_msg->reason, "Success", strlen("Success")); break; default: resp_msg->status = ESubFAILED; strncpy(resp_msg->reason, "Failed", strlen("Failed")); break; } if(ds == EDistType_Data) { Object_DBG("ObjectDistQueryRespMsgSend: Dist Query Request Message send with payload %s/%s:%d dsType:%d Status:%d Reason:%s", resp_msg->objName, resp_msg->distName, resp_msg->data, resp_msg->dsType, resp_msg->status, resp_msg->reason); } else if(ds == EDistType_String){ Object_DBG("ObjectDistQueryRespMsgSend: Dist Query Request Message send with payload %s/%s:%s dsType:%d Status:%d Reason:%s", resp_msg->objName, resp_msg->distName, resp_msg->str, resp_msg->dsType, resp_msg->status, resp_msg->reason); } err = SysComSendMsg(msg); ObjectDistQueryRespMsgSend_RET: mico_rtos_unlock_mutex(&ObjectMutex); return err; }
/* ConfirmSellItem is called when client recieves ok from server */ T_void StoreConfirmSellItem (T_void) { T_word32 amount; T_byte8 stmp[64]; T_byte8 stmp2[16]; T_3dObject *p_obj; T_inventoryItemStruct *p_inv; DebugRoutine ("StoreConfirmSellItem"); DebugCheck (G_itemToSell != NULL); /* move the item from the store inventory to the player inventory */ // if (G_itemToSell->numitems > 1) // { if (G_itemToSell->itemdesc.type==EQUIP_OBJECT_TYPE_QUIVER) { /* don't make a new item */ /* just add 12 arrows */ Effect (EFFECT_TAKE_AMMO, EFFECT_TRIGGER_GET, G_itemToSell->itemdesc.subtype, 12, 0, G_itemToSell->object); } else { p_obj=ObjectCreateFake(); DebugCheck (p_obj != NULL); ObjectSetType (p_obj,ObjectGetType(G_itemToSell->object)); ObjectSetAngle (p_obj,0x4000); p_inv=InventoryTakeObject (INVENTORY_PLAYER,p_obj); /* set 'quick pointer' for mouse hand */ InventorySetMouseHandPointer (p_inv->elementID); InventoryDoEffect(EFFECT_TRIGGER_GET,EQUIP_LOCATION_MOUSE_HAND); } /* identify arrow type for player */ StatsPlayerIdentify(ObjectGetType(G_itemToSell->object)); /* force mouse hand picture update */ // ControlSetObjectPointer (p_inv->object); // StatsChangePlayerLoad(ObjectGetWeight(G_itemToSell->object)); // G_itemToSell->numitems--; // } // else // { // element=InventoryTransferItemBetweenInventories( // G_itemToSell, // INVENTORY_STORE, // INVENTORY_PLAYER); // DebugCheck (element != DOUBLE_LINK_LIST_ELEMENT_BAD); /* set the mouse hand pointer */ // InventorySetMouseHandPointer (element); // } if (G_houseMode==FALSE) { /* go ahead and sell the item to the player */ /* subtract the cost of this item */ if (EffectPlayerEffectIsActive(PLAYER_EFFECT_GOD_MODE)==FALSE) { amount=ObjectGetValue(G_itemToSell->object); StoreConvertCurrencyToString (stmp,amount); if (G_itemToSell->itemdesc.type==EQUIP_OBJECT_TYPE_QUIVER) { switch (G_itemToSell->itemdesc.subtype) { case BOLT_TYPE_NORMAL: strcpy (stmp2,"normal"); break; case BOLT_TYPE_POISON: strcpy (stmp2,"green"); break; case BOLT_TYPE_PIERCING: strcpy (stmp2,"brown"); break; case BOLT_TYPE_FIRE: strcpy (stmp2,"red"); break; case BOLT_TYPE_ELECTRICITY: strcpy (stmp2,"yellow"); break; case BOLT_TYPE_MANA_DRAIN: strcpy (stmp2,"purple"); break; case BOLT_TYPE_ACID: strcpy (stmp2,"white"); break; default: DebugCheck (0); /* bad bolt! */ break; } MessagePrintf ("^009You bought 12 %s arrows for %s",stmp2,stmp); } else MessagePrintf ("^009Sold!! for %s",stmp); StatsChangePlayerTotalCarriedWealth(-(T_sword32)amount); } else { MessageAdd ("^009Well... You're a god... it's free."); } // StoreUIUpdateGraphics(); } /* resort the inventory */ InventoryReorder (INVENTORY_STORE,TRUE); /* redraw the inventory window */ InventoryDrawInventoryWindow(INVENTORY_STORE); G_itemToSell=NULL; DebugEnd(); }
/* alternate inventory */ T_void StoreHandleTransaction (E_mouseEvent event, T_word16 x, T_word16 y, T_buttonClick buttons) { T_inventoryItemStruct* itemInHand=NULL; T_inventoryItemStruct* itemInStore=NULL; T_doubleLinkListElement element=DOUBLE_LINK_LIST_ELEMENT_BAD; DebugRoutine ("StoreHandleTransaction"); /* first, see if we've selected the alternate inventory */ if (InventoryFindInventoryWindow(x,y)==INVENTORY_STORE) { /* ok, we clicked on it. */ /* do we have something in the mouse hand currently? */ itemInHand=InventoryCheckItemInMouseHand(); if (itemInHand != NULL) { if (G_houseMode==FALSE) { /* we must be trying to sell this item */ /* check to see if the store wants to buy it */ if (StoreWillBuy(itemInHand->itemdesc.type) && StoreGetBuyValue(itemInHand)>0) { /* notify the server that the store wants to buy an item */ /* from the player */ StoreRequestBuyItem(itemInHand); } else { MessageAdd ("^005I don't want to buy that from you."); } } else { StoreRequestBuyItem(itemInHand); } } else { if (G_houseMode==FALSE) { /* we must be trying to buy something */ /* is there an item in this location ? */ itemInStore=InventoryCheckItemInInventoryArea(x,y); if (itemInStore != NULL) { /* there's something here. Can we buy it? */ if (StatsGetPlayerTotalCarriedWealth()>=ObjectGetValue(itemInStore->object) || EffectPlayerEffectIsActive(PLAYER_EFFECT_GOD_MODE)) { /* notify the server that the store wants to sell */ /* an item to the player */ StoreRequestSellItem (itemInStore); } else { MessageAdd ("^005You can't afford that!"); } } } else { itemInStore=InventoryCheckItemInInventoryArea(x,y); if (itemInStore != NULL) { StoreRequestSellItem(itemInStore); } } } } /* notify callback */ if (G_controlCallback != NULL) G_controlCallback(); DebugEnd(); }
T_word16 StoreGetBuyValue (T_inventoryItemStruct *p_inv) { T_word16 buyValue=0; T_word16 objtype; DebugRoutine ("StoreGetBuyValue"); if (StoreWillBuy(p_inv->itemdesc.type)) { objtype=ObjectGetType(p_inv->object); if (objtype==60 || objtype==117) { /* bag of gold */ if (ObjectGetAccData(p_inv->object)!=0) { buyValue=ObjectGetAccData(p_inv->object)*100; } else { buyValue=1000; } } else if ((objtype>=110 && objtype<=113) || objtype==56) { /* gems */ buyValue=ObjectGetValue(p_inv->object); } else if (objtype==412 || objtype==413 || objtype==414 || objtype==425 || objtype==433) { /* treasure rings */ buyValue=ObjectGetValue(p_inv->object); } else if (objtype>=144 && objtype<=150) { /* quivers */ if (ObjectGetAccData(p_inv->object)!=0) { buyValue=ObjectGetValue(p_inv->object)* ObjectGetAccData(p_inv->object)/3; } else { buyValue=ObjectGetValue(p_inv->object)/3; } } else if (objtype >= 300 && objtype <= 317) { /* won't buy runes */ buyValue=0; } else { buyValue=(ObjectGetValue(p_inv->object))/3; } } DebugEnd(); return (buyValue); }