Пример #1
0
void World::lookAtShowcaseItem(Player *cp, uint8_t showcase, unsigned char position) {

    ScriptItem titem;

    if (cp->isShowcaseOpen(showcase)) {
        Container *ps = cp->getShowcaseContainer(showcase);

        if (ps != nullptr) {
            Container *tc;

            if (ps->viewItemNr(position, titem, tc)) {
                std::shared_ptr<LuaItemScript> script = Data::CommonItems.script(titem.getId());
                ScriptItem n_item = titem;

                n_item.type = ScriptItem::it_container;
                n_item.pos = cp->getPosition();
                n_item.owner = cp;
                n_item.itempos = position;
                n_item.inside = ps;

                if (script && script->existsEntrypoint("LookAtItem")) {
                    script->LookAtItem(cp, n_item);
                    return;
                }

                lookAtItemScript->lookAtItem(cp, n_item);
            }
        }
    }
}
Пример #2
0
bool Container::viewItemNr(TYPE_OF_CONTAINERSLOTS nr, ScriptItem &item, Container *&cc) {
    auto it = items.find(nr);

    if (it != items.end()) {
        item = it->second;
        item.type = ScriptItem::it_container;
        item.itempos = nr;
        item.inside = this;

        if (item.isContainer()) {
            auto iterat = containers.find(nr);

            if (iterat != containers.end()) {
                cc = iterat->second;
            } else {
                cc = new Container(item.getId());
            }
        } else {
            cc = nullptr;
        }

        return true;
    } else {
        items.erase(nr);
        cc = nullptr;
        return false;
    }
}
Пример #3
0
std::vector<ruleset::UserScriptInfo> ScriptsListView::userScripts() {
  std::vector<ruleset::UserScriptInfo> result;
  BOOST_FOREACH(OSItem* item,items()) {
    ScriptItem* scriptItem = qobject_cast<ScriptItem*>(item);
    if (boost::optional<ruleset::UserScriptInfo> info = scriptItem->userScriptInfo()) {
      result.push_back(*info);
    }
  }
void World::changeQuality(ScriptItem item, short int amount) {
    short int tmpQuality = ((amount+item.getDurability())<100) ? (amount + item.getQuality()) : (item.getQuality() - item.getDurability() + 99);

    if (tmpQuality%100 > 0) {
        item.setQuality(tmpQuality);
        changeItem(item);
    } else {
        erase(item, item.getNumber());
    }
}
void ScriptFolderListView::saveOSArguments() {
  for (std::map<openstudio::path, ScriptsListView *>::const_iterator lit = m_scriptsListViews.begin(),
       litEnd = m_scriptsListViews.end(); lit != litEnd; ++lit)
  {
    std::vector<OSItem *> listItems = lit->second->items();
    for (auto & listItem : listItems)
    {
      ScriptItem* scriptItem = qobject_cast<ScriptItem*>(listItem);
      if (scriptItem) {
        scriptItem->saveArgumentsToDb();
      }
    }
  }
}
bool World::erase(ScriptItem item, int amount) {
    if (amount > item.getNumber()) {
        amount = item.getNumber();
    }

    if (item.type == ScriptItem::it_inventory || item.type == ScriptItem::it_belt) {
        //Wenn Item rechts belegt und links ein Belegt ist [Zweihanditem] das Belegt mit l�schen
        if (item.itempos == RIGHT_TOOL && (item.owner->GetItemAt(LEFT_TOOL)).getId() == BLOCKEDITEM) {
            item.owner->increaseAtPos(LEFT_TOOL, -255);
        } else if (item.itempos == LEFT_TOOL && (item.owner->GetItemAt(RIGHT_TOOL)).getId() == BLOCKEDITEM) {
            item.owner->increaseAtPos(RIGHT_TOOL, -255);
        }

        item.owner->increaseAtPos(item.itempos, -amount);
        return true;
    }
    //Item befindet sich auf einen Feld am Boden liegend.
    else if (item.type == ScriptItem::it_field) {
        try {
            Field &field = fieldAt(item.pos);
            bool erased=false;
            field.increaseItemOnStack(-amount, erased);

            if (erased) {
                sendRemoveItemFromMapToAllVisibleCharacters(item.pos);
            } else {
                sendSwapItemOnMapToAllVisibleCharacter(item.getId(), item.pos, item);
            }

            return true;
        } catch (FieldNotFound &) {
            logMissingField("erase", item.pos);
            return false;
        }
    } else if (item.type == ScriptItem::it_container) {
        if (item.inside) {
            item.inside->increaseAtPos(item.itempos, -amount);
            sendContainerSlotChange(item.inside, item.itempos);
            return true;
        } else {
            return false;
        }
    }

    return false;
}
Пример #7
0
void Container::addContentToList(std::vector<ScriptItem> &list) {
    for (auto it = items.begin(); it != items.end(); ++it) {

        ScriptItem item = it->second;
        item.type = ScriptItem::it_container;
        item.itempos = it->first;
        item.inside = this;
        list.push_back(item);

        if (item.isContainer()) {
            auto iterat = containers.find(it->first);

            if (iterat != containers.end()) {
                iterat->second->addContentToList(list);
            }
        }

    }
}
void InterpreterService_impl::interpretMain(const char* expr)
{
    ostream& os = MessageView::instance()->cout();
    
    os << (format(_("%1%: interpret(\"%2%\")")) % item->name() % expr) << endl;

    ScriptItem* scriptItem = item->findOwnerItem<ScriptItem>();
    if(!scriptItem){
        os <<(format(_("The owner script item of %1% is not found. The interpret function cannot be executed."))
              % item->name()) << endl;
    } else {
        if(scriptItem->isRunning()){
            os << (format(_("Owner script item \"%1%\" is running now. The interpret function cannot be executed."))
                   % scriptItem->name()) << endl;
        } else {
            if(!scriptItem->executeCode(expr)){
                os << (format(_("Executing the script given to the interpret function failed."))) << endl;
            } else {
                if(!scriptItem->waitToFinish()){
                    os << (format(_("The script does not return.")) % item->name()) << endl;
                } else {
                    result = scriptItem->resultString();
                    if(!result.empty()){
                        os << (format(_("%1%: interpret() returns %2%.")) % item->name() % result) << endl;
                    } else {
                        os << (format(_("%1%: interpret() finished.")) % item->name()) << endl;
                    }
                }
            }
        }
    }
}
bool World::changeItem(ScriptItem item) {
    if (item.type == ScriptItem::it_inventory || item.type == ScriptItem::it_belt) {
        item.owner->items[ item.itempos ] = (Item)item;

        //Wenn character ein Spieler ist ein update schicken
        if (item.owner->getType() == Character::player) {
            dynamic_cast<Player *>(item.owner)->sendCharacterItemAtPos(item.itempos);
        }

        item.owner->updateAppearanceForAll(true);
        return true;
    } else if (item.type == ScriptItem::it_field) {
        try {
            Field &field = fieldAt(item.pos);
            Item it;

            if (field.takeItemFromStack(it)) {
                field.addItemOnStack(static_cast<Item>(item));

                if (item.getId() != it.getId() || it.getNumber() != item.getNumber()) {
                    sendSwapItemOnMapToAllVisibleCharacter(it.getId(), item.pos, item);
                }
            }

            return true;
        } catch (FieldNotFound &) {
            return false;
        }
    } else if (item.type == ScriptItem::it_container) {
        if (item.inside) {
            item.inside->changeItem(item);
            sendContainerSlotChange(item.inside, item.itempos);
            return true;
        }
    }

    return false;
}
ItemStruct World::getItemStats(ScriptItem item) {
    const auto &data = Data::Items[item.getId()];
    return data;
}
Пример #11
0
std::list<BlockingObject> World::LoS(const position &startingpos, const position &endingpos) const {
    std::list<BlockingObject> ret;
    ret.clear();
    bool steep = std::abs(startingpos.y - endingpos.y) > std::abs(startingpos.x - endingpos.x);
    short int startx=startingpos.x;
    short int starty=startingpos.y;
    short int endx=endingpos.x;
    short int endy=endingpos.y;

    if (steep) {
        //change x,y values for correct algorithm in negativ range
        short int change;
        change = startx;
        startx = starty;
        starty = change;
        change = endx;
        endx = endy;
        endy = change;
    }

    bool swapped = startx > endx;

    if (swapped) {
        short int change;
        change = startx;
        startx = endx;
        endx = change;
        change = starty;
        starty = endy;
        endy = change;

    }

    short int deltax = endx - startx;
    short int deltay = std::abs(endy - starty);
    short int error = 0;
    short int ystep=1;
    short int y = starty;

    if (starty > endy) {
        ystep = -1;
    }

    for (short int x = startx; x <= endx; ++x) {
        if (!(x == startx && y == starty) && !(x == endx && y == endy)) {
            BlockingObject bo;
            Field *temp;
            position pos{x, y, startingpos.z};

            if (steep) {
                pos.x = y;
                pos.y = x;
            }

            if (GetPToCFieldAt(temp, pos)) {
                if (temp->IsPlayerOnField()) {
                    bo.blockingType = BlockingObject::BT_CHARACTER;
                    bo.blockingChar = findCharacterOnField(pos);

                    if (swapped) {
                        ret.push_back(bo);
                    } else {
                        ret.push_front(bo);
                    }
                } else {
                    ScriptItem it;

                    for (size_t i = 0; i < temp->NumberOfItems(); ++i) {
                        auto testItem = temp->getStackItem(i);
                        
                        if (testItem.getVolume() > it.getVolume()) {
                            it = testItem;
                        }
                    }
                        
                    if (it.isLarge()) {
                        bo.blockingType = BlockingObject::BT_ITEM;
                        it.pos = pos;
                        it.type = ScriptItem::it_field;
                        bo.blockingItem = it;

                        if (swapped) {
                            ret.push_back(bo);
                        } else {
                            ret.push_front(bo);
                        }
                    }
                }
            }
        }

        error += deltay;

        if (2*error >= deltax) {
            y+=ystep;
            error -= deltax;
        }
    }

    return ret;
}