View Single Post
  #11  
Old 01-22-2014, 01:25 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Torankusu View Post
wouldnt this essentially mean that all items that the character owns with an item id of 5 would take on these chsracteristics?
Yep, using a separate table would be the more 'normalized' way to do it though. You could have a 100 enchantments for the same item if you wanted.

The tricky part is deciding how you want to query and load the information. I would probably do:

1. Load characteritem data
2. Load and apply enchantments using array of character item ids

I.e.

SELECT CharacterItems.*, Items.*
FROM CharacterItems, Items
WHERE CharacterID = 1 AND Items.ID = CharacterItems.ItemID;

SELECT CharacterItemID, Enchantment, EnchantmentValue
FROM Enchantments
WHERE CharacterItemID IN (1, 2, 3)

I wrote a function that generates an escaped IN clause with an array of data:

PHP Code:
// usage: generateInClause("column", {1,2,3});
public function generateInClause(columnitems) {
  
temp.clause column " IN (";
  
temp.last   items.size() - 1;
  for (
temp.0temp.items.size(); temp.i++) {
    
temp.item items[temp.i];
    if (
temp.== temp.last) {
      
temp.clause @= "'" escapestring2(temp.item) @ "'";
    } else {
      
temp.clause @= "'" escapestring2(temp.item) @ "',";
    }
  }
  
temp.clause @= ")";
  return 
temp.clause.link();

__________________
Quote:
Reply With Quote