Witaj
Gość

Wątek: [analiza kodu] Własny quest + własne quest itemy  (Przeczytany 3881 razy)

  • Wiadomości: 3

  • Pochwał: 0

[analiza kodu] Własny quest + własne quest itemy
« dnia: Grudzień 11, 2009, 11:15:58 am »
Chcę zrobić własnego questa, nieco już zmodyfikowałem kod, ale brak doświadczenia w tworzeniu questów oraz mała znajomość Jythona zmuszają mnie do zasięgnięcia rady.

# version 0.01
# by NoAd

import sys
from net.sf.l2j import Config
from net.sf.l2j.gameserver.model.quest import State
from net.sf.l2j.gameserver.model.quest import QuestState
from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest

qn = "90090_Adam"

#NPCs
ADAM = 90090
FIRST = 90091
SECOND = 90092
THIRD = 90093

#Rewards
PASS_TO_LL_VILLAGE = XX
WAND_PART = XXX

# Main Quest Code
class Quest (JQuest):

  def __init__(self,id,name,descr):
    JQuest.__init__(self,id,name,descr)
    self.questItemIds = range(3417,3428)+range(10164,10166)

  def onEvent (self,event,st):
    id = st.getState()
    if id == State.CREATED :
      if event == "talk" :
        st.set("progress","0")
      if event == "talk1" :
        st.giveItems(WAND_PART)
        return "90091_1.htm"
      if event == "talk2" :
        st.set("progress", str(st.getInt("progress") | 1))
        st.giveItems(WAND_PART)
        return "90092_1.htm"
      if event == "talk3" :
        st.set("progress", str(st.getInt("progress") | 2))
        st.giveItems(WAND_PART)
        return "90093_1.htm"
      if event == "talk4" :
        st.set("progress", str(st.getInt("progress") | 4))
        st.takeItems(WAND_PART,3)
        return "90090_4.htm"
    return

  def onTalk (self,npc,player):
    htmltext = "<html><body>You are either not on a quest that involves this NPC, or you don't meet this NPC's minimum quest requirements.</body></html>"
    st = player.getQuestState(qn)
    if not st : return htmltext

    npcId = npc.getNpcId()
    id = st.getState()
    if npcId != ADAM and id == State.STARTED:
      if st.get("step")!="" : return htmltext

    if id == State.COMPLETED: st.setState(State.CREATED)
    if npcId == ADAM :
      if id == State.CREATED  :
         if player.getLevel() < 60 :
            st.exitQuest(1)
            return "90090_low_level.htm"
         return "Start.htm"
      if id == State.STARTED
            st.giveItems(LIST_OF_NPC)
      if id == State.STARTED :
        if st.getInt("progress") == 7 :
           return "Talked.htm"
        return "90090_PENDING_TALK.htm"
    elif id == State.STARTED:
      if npcId == FIRST :
         return "90091_2.htm"
      elif npcId == SECOND :
         return "90092_2.htm"
      elif npcId == THIRD :
         return "90093_2.htm"
    return

# Quest class and state definition
QUEST       = Quest(90090, qn, "Pass to LifeLand Village")

# Quest NPC starter initialization
QUEST.addStartNpc(ADAM)

# Quest NPC initialization
QUEST.addTalkId(ADAM)

QUEST.addTalkId(FIRST)
QUEST.addTalkId(SECOND)
QUEST.addTalkId(THIRD)

Kod jest przebudowany z innego questa stąd może tu być nieco zbędnych linii.
Generalnie q chciałbym aby wyglądał tak:
Start u NPC: ADAM
Następnie odwiedzamy npc FIRST,SECOND,THIRD (dowolna kolejność) każdy z nich ma dać nam q itema (WAND_PART)
Po odwiedzaniu wszystkich npc wracamy do startowego a ten mam daje w nagrodę PASS_TO_LL_VILLAGE.

I tu dodatkowe pytanie: quest itemy z tego co wiem wystarczy dodać w etcitem w bazie danych, i tu pytania: 1. gdzie zdefiniować jak ma wyglądać nowo dodany item ? czyżby to była tabela item_icon ?
2. gdzie mogę zdefiniować opis quest itema ?

self.questItemIds = range(3417,3428)+range(10164,10166)tutaj zapewne maja być przedziały q itemów, które utworzę ?

Mam nadzieję że przejrzyście przekazałem swój problem. I że zbytnio nikogo nie zirytuję ^^

Edit:
Zapomniałem dodać że serwer to L2JServer
« Ostatnia zmiana: Grudzień 11, 2009, 11:44:27 am wysłana przez NoAd »
serwer: l2jserwer


  • Wiadomości: 56

  • Pochwał: 1

Odp: [analiza kodu] Własny quest + własne quest itemy
« Odpowiedź #1 dnia: Grudzień 11, 2009, 03:05:39 pm »
aby dodac nowe, nieistniejace itemy musisz modyfikowac klienta gry co jest zakazane


  • *******
  • Wiadomości: 1092

  • Pochwał: 22

Odp: [analiza kodu] Własny quest + własne quest itemy
« Odpowiedź #2 dnia: Grudzień 11, 2009, 04:26:05 pm »
Można w bazie zrobić nowy etcitem, ale wiadomo, że potem wymaga to modyfikacji clienta (dodanie paru linijek do itemsname itp)


  • Wiadomości: 3

  • Pochwał: 0

Odp: [analiza kodu] Własny quest + własne quest itemy
« Odpowiedź #3 dnia: Grudzień 11, 2009, 09:47:54 pm »
Czyli lepszym wyjściem było by w bazie danych jakiś event item zmienić na quest item, untradeable, unsellable, i do niego zrobić odwołanie jak mniemam ?

---- co do kodu na chwile obecną wygląda tak:
# version 0.02
# by NoAd

import sys
from net.sf.l2j import Config
from net.sf.l2j.gameserver.model.quest import State
from net.sf.l2j.gameserver.model.quest import QuestState
from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest

qn = "90090_Adam"

#NPCs
ADAM = 90090
FIRST = 90091
SECOND = 90092
THIRD = 90093

#Quest items
PASS_TO_LL_VILLAGE = 9009001
WAND_PART = 9009000
 
# Main Quest Code
class Quest (JQuest):

  def __init__(self,id,name,descr):
    JQuest.__init__(self,id,name,descr)

  def onEvent (self,event,st):
    id = st.getState()
    if id == State.CREATED :
      if event == "talk" :
        st.set("progress","0")
        if event == "details" :
          return "90090_confirm.htm"
      elif event == "agree" :
        st.setState(State.STARTED)
        st.set("step","STARTED")
        st.playSound("ItemSound.quest_accept")
      if event == "talk1" and st.get("step") == "STARTED":
        st.set("progress", str(st.getInt("progress") | 4))
        st.giveItems(WAND_PART)
        return "90091_1.htm"
      if event == "talk2" and st.get("step") == "STARTED" :
        st.set("progress", str(st.getInt("progress") | 1))
        st.giveItems(WAND_PART)
        return "90092_1.htm"
      if event == "talk3" and st.get("step") == "STARTED" :
        st.set("progress", str(st.getInt("progress") | 2))
        st.giveItems(WAND_PART)
        return "90093_1.htm"
      if event == "talk4" and st.getInt("progress") == 7:
        st.takeItems(WAND_PART,3)
        st.giveItems(PASS_TO_LL_VILLAGE)
        return "90090_4.htm"
    return

  def onTalk (self,npc,player):
    htmltext = "<html><body>You are either not on a quest that involves this NPC, or you don't meet this NPC's minimum quest requirements.</body></html>"
    st = player.getQuestState(qn)
    if not st : return htmltext

    npcId = npc.getNpcId()
    id = st.getState()

    if id == State.COMPLETED: st.setState(State.CREATED)
    if npcId == ADAM :
      if id == State.CREATED  :
         if player.getLevel() < 60 :
            st.exitQuest(1)
            return "90090_low_level.htm"
         return "Start.htm"
      if id == State.STARTED
            st.giveItems(LIST_OF_NPC)
      if id == State.STARTED :
        if st.getInt("progress") == 7 :
           return "Talked.htm"
        return "90090_PENDING_TALK.htm"
    elif id == State.STARTED:
      if npcId == FIRST :
         return "90091_2.htm"
      elif npcId == SECOND :
         return "90092_2.htm"
      elif npcId == THIRD :
         return "90093_2.htm"
    return

# Quest class and state definition
QUEST       = Quest(90090, qn, "Pass to LifeLand Village")

# Quest NPC starter initialization
QUEST.addStartNpc(ADAM)

# Quest NPC initialization
QUEST.addTalkId(ADAM)
QUEST.addTalkId(FIRST)
QUEST.addTalkId(SECOND)
QUEST.addTalkId(THIRD)
I taka moja mała prośba czy mógłby to ktoś tak ogólnie przejrzeć czy kod jest spójny logicznie ?
serwer: l2jserwer


  • ******
  • Wiadomości: 1390

  • Pochwał: 15

  • Urażona dzidzia, urażona dzidzia!
Odp: [analiza kodu] Własny quest + własne quest itemy
« Odpowiedź #4 dnia: Grudzień 11, 2009, 09:58:12 pm »
    if id == State.COMPLETED: st.setState(State.CREATED)
    if npcId == ADAM :
      if id == State.CREATED  :
         if player.getLevel() < 60 :
            st.exitQuest(1)
            return "90090_low_level.htm"
         return "Start.htm"
      if id == State.STARTED
            st.giveItems(LIST_OF_NPC)
      if id == State.STARTED :
        if st.getInt("progress") == 7 :
           return "Talked.htm"
        return "90090_PENDING_TALK.htm"
    elif id == State.STARTED:
      if npcId == FIRST :
         return "90091_2.htm"
      elif npcId == SECOND :
         return "90092_2.htm"
      elif npcId == THIRD :
         return "90093_2.htm"
    return

swicth/case nie slyszal ?


  • Wiadomości: 3

  • Pochwał: 0

Odp: [analiza kodu] Własny quest + własne quest itemy
« Odpowiedź #5 dnia: Grudzień 12, 2009, 11:40:09 am »
Słyszał, słyszał ale w pythonie nigdy nie robił.

Czy teraz lepiej ?

W pliku script.cfg dodałem questa linią:
custom/90090_Adam/__init__.py
Jednak po wywołaniu w grze odnośnika:
<a action="bypass -h npc_%objectId%_Quest">Quest</a>
Wyskakuje że nie spełniam wymogów by pogadać z npc. (tak jakby nie odczytało pliku skryptu) Czy coś jeszcze powinienem gdzieś dodać ?

Czy teraz lepiej ?
# version 0.03
# by NoAd

import sys
from net.sf.l2j import Config
from net.sf.l2j.gameserver.model.quest import State
from net.sf.l2j.gameserver.model.quest import QuestState
from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest

qn = "90090_Adam"

#NPCs
ADAM = 90090
FIRST = 90091
SECOND = 90092
THIRD = 90093

#Quest items
PASS_TO_LL_VILLAGE = 9009001
WAND_PART = 9009000
 
# Main Quest Code
class Quest (JQuest):

  def __init__(self,id,name,descr):
    JQuest.__init__(self,id,name,descr)

  def onEvent (self,event,st):
    id = st.getState()
    values.get(var, do_default_stuff)()
   
    if id == State.CREATED :   
      result = {
        'talk': lambda
          str(st.set("progress","0")),
        'agree': lambda
          st.setState(State.STARTED)
          st.set("step","STARTED")
          st.playSound("ItemSound.quest_accept"),
        'details': lambda
          return "90090_confirm.htm" 
        'talk1': lambda
          if st.get("step") == "STARTED":
            st.set("progress", str(st.getInt("progress") | 4))
            st.giveItems(WAND_PART)
              return "90091_1.htm",
        'talk2': lambda
          if st.get("step") == "STARTED":
            st.set("progress", str(st.getInt("progress") | 1))
            st.giveItems(WAND_PART)
              return "90092_1.htm",
        'talk3': lambda
          if st.get("step") == "STARTED":
            st.set("progress", str(st.getInt("progress") | 2))
            st.giveItems(WAND_PART)
              return "90093_1.htm",
        'talk4': lambda
          if st.getInt("progress") == 7:
            st.takeItems(WAND_PART,3)
            st.giveItems(PASS_TO_LL_VILLAGE)
              return "90090_4.htm",
      }event(return "error.htm")

  def onTalk (self,npc,player):
    htmltext = "<html><body>You are either not on a quest that involves this NPC, or you don't meet this NPC's minimum quest requirements.</body></html>"
    st = player.getQuestState(qn)
    if not st : return htmltext

    npcId = npc.getNpcId()
    id = st.getState()
    if id == State.COMPLETED: st.setState(State.CREATED)
   
    result = {
      ADAM: lambda
        if id == State.CREATED  :
          if player.getLevel() < 60 :
            st.exitQuest(1)
          return "90090_low_level.htm"
        return "Start.htm"
        if id == State.STARTED
        return "90090_started.htm"
        if id == State.STARTED :
          if st.getInt("progress") == 7 :
          return "Talked.htm"
        return "90090_PENDING_TALK.htm",
      FIRST: lambda
        if id == State.STARTED  :
          return "90091_2.htm",
      SECOND: lambda
        if id == State.STARTED  :
        return "90092_2.htm"
      THIRD: lambda
        if id == State.STARTED  :
        return "90093_2.htm"
    }npcId(return "error.htm")

# Quest class and state definition
QUEST       = Quest(90090, qn, "Pass to LifeLand Village")

# Quest NPC starter initialization
QUEST.addStartNpc(ADAM)

# Quest NPC initialization
QUEST.addTalkId(ADAM)
QUEST.addTalkId(FIRST)
QUEST.addTalkId(SECOND)
QUEST.addTalkId(THIRD)
serwer: l2jserwer